网上发布信息的网站怎么做,网站建设费摊销几年,网站建设需要哪些常用技术,抖音小程序制作1、创建表 # 基本语法#xff1a;
create table 表名(列名 类型 是否可以为空 默认值 自增 主键#xff0c;列名 类型 是否可以为空
)ENGINEInnoDB DEFAULT CHARSETutf8not null # 不可以为空
default 1 # 默认值为1
auto_increment # 自增
primary …1、创建表 # 基本语法
create table 表名(列名 类型 是否可以为空 默认值 自增 主键列名 类型 是否可以为空
)ENGINEInnoDB DEFAULT CHARSETutf8not null # 不可以为空
default 1 # 默认值为1
auto_increment # 自增
primary key # 主键
constraint 外键名 foreign key (从表字段’自己‘) references 主表(主键字段) # 外键 2、查看表结构 desc 表名 3、删除表 drop table 表名 4、清空表 # 表还存在表内容清空delete from 表名
truncate table 表名 5、修改表 # 添加列alter table 表名 add 列名 类型 # 删除列alter table 表名 drop column 列名 # 修改列数据类型alter table 表名 modify column 列名 类型; # 修改列数据类型和列名alter table 表名 change 原列名 新列名 类型; # 添加主键alter table 表名 add primary key(列名);
# 删除主键alter table 表名 drop primary key; # 添加外键alter table 从表 add constraint 外键名称形如FK_从表_主表 foreign key 从表(外键字段) references 主表(主键字段);
# 删除外键alter table 表名 drop foreign key 外键名称 # 修改默认值ALTER TABLE testalter_tbl ALTER i SET DEFAULT 1000;
# 删除默认值ALTER TABLE testalter_tbl ALTER i DROP DEFAULT; # 更改表名rename table 原表名 to 新表名; #增加表字段altertable法。
1 语法 altertable 表名 add 字段 类型 其他
2 插入列名为sex。
mysql alter table student add sex char(4);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql select * from student;
-------------------------------
| id | name | age | dept | sex |
-------------------------------
| 2 | oldsuo | 0 | NULL | NULL |
| 3 | kangknag | 0 | NULL | NULL |
| 4 | kangkang | 0 | NULL | NULL |
-------------------------------
3 rows in set (0.00 sec)
3 插入名为suo列在name后面。
mysql alter table student add suo int(4) after name;
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
4 插入名为qq列在第一。
mysql alter table student add qq varchar(15) first;
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0 参考https://www.cnblogs.com/suoning/articles/5769141.html 转载于:https://www.cnblogs.com/cui0x01/p/8640431.html