创建表

mysql> create table 表名(
    -> 列名 数据类型 是否为空 auto_increment,
    -> 列名 数据类型 是否为空...
    -> ...
    -> 列名 数据类型 是否为空... default 值,
    -> primary key(列名1,列名2...))engine=myisam;
  1. 可以用last_insert_id()获取最后一个auto_increment的值
  2. 允许使用NULL值的列可以在插入行时不给出该列值,NULL值就是没有值,不是空串
  3. 不允许函数作为默认值,只允许常量作为默认值
  4. 应尽量使用默认值而不是NULL得列

更新表

 alter table 表名
    -> add 列名 数据类型
    -> drop column 列名;

 用alter table定义外键

alter table 表名 add constraint 外键约束名 foreign key(列名) references 引用外键表(列名) 

 删除表

drop table 表名;

重命名表

mysql> rename table 旧表名 to 新表名,旧表名 to 新表明...;

 

相关文章:

  • 2021-07-30
  • 2021-06-29
  • 2021-10-19
  • 2022-02-12
  • 2021-12-03
  • 2022-12-23
  • 2022-01-09
猜你喜欢
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
  • 2022-01-23
  • 2021-11-30
  • 2022-01-13
相关资源
相似解决方案