zoukankan      html  css  js  c++  java
  • mysql 杂记

    创建数据表的语法形式

    CREATE TABLE <表名>
    (
        列名1 数据类型 [列级别约束条件] [默认值]
        列名2 数据类型 [列级别约束条件] [默认值]
        ...
        [表级别约束条件]
    );
     
    主键约束
    单字段主键
    字段名 数据类型 PRIMARY KEY
     
    多字段联合主键
    PRIMARY KEY [字段1,字段2....]
     
    not null 非空约束
    unique唯一性约束
     
    默认约束
    字段名 数据类型 default 默认值
     
    表属性值自动增加
    字段名 数据类型 auto_increment

    外键约束

    [constraint <外键名>] FOREIGN KEY 字段名1[,字段名2,...] references<主表名> 主键列1[,主键列2,...]
     
    只有两个表都是InnoDB引擎才可以使用外键约束
    外键字段的类型要一样
     
    删除数据表
    drop table [if exist] <表名1> <表名2> ...
     
    修改数据表
     
    修改表名
    alter table <旧表名> rename [to] <新表名>;
     
     
    修改字段类型
    alter table <表名> modify <字段名> <数据类型>
     
    修改字段名
    alter table <表名> change <旧字段名> <新字段名> <新数据类型>;
     
    添加字段
    alter table <表名> add <新字段名> <数据类型> [约束条件]
    [first | after 已存在字段名]
    first和after规定字段位置,不写则在最后添加字段
     
    修改字段排序
    alter table <表名> modify <字段1> <数据类型> first|after <字段2>
     
    更改表的存储引擎
    alter table <表名> engine = <更改后的存储引擎名>;
     
    删除字段
    alter table <表名> drop <字段名>;
     
    删除表的外键约束
    alter table <表名> droop foreign key <外键约束名>
  • 相关阅读:
    【LeetCode】048. Rotate Image
    【LeetCode】036. Valid Sudoku
    【LeetCode】060. Permutation Sequence
    【LeetCode】001. Two Sum
    【LeetCode】128. Longest Consecutive Sequence
    【LeetCode】081. Search in Rotated Sorted Array II
    【LeetCode】033. Search in Rotated Sorted Array
    顺时针打印矩阵
    矩形覆盖
    二维数组中的查找
  • 原文地址:https://www.cnblogs.com/cplover/p/3372195.html
Copyright © 2011-2022 走看看