标签:add log default show 技术分享 reference com student lap
语法:CREATE TABLE table_name (column_name column_type);
CREATE TABLE student(
-> id INT NOT NULL AUTO_INCREMENT,
-> name CHAR(32) NOT NULL,
-> age INT NOT NULL,
-> register_data DATE,
-> PRIMARY KEY(id)
-> );
auto_increment 表示:自增1。写入内容为空时,默认从1,2,3...往下填充写入表格中。primary key: 表示约束(不能重复且不能为空); 加速查找not null: 不为空
show tables; -->查看有哪些表 desc student; --> 查看student表的信息 show create table student; -->查看表student创建的信息

#drop table 表名 drop table student;
方法:
添加列: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 表名 modify 列名 int, 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;
1.增加 ALTER TABLE student ADD sex CHAR(32); #-->增加一列 2.删除 ALTER TABLE student DROP sex; #-->删除一列 3.修改表名 ALTER TABLE student RENAME TO students; #-->重命名 4.修改列名 ALTER TABLE students CHANGE regisiter_date register_date DATE; #change 字段名,类型都可以改,modify只能改类型
标签:add log default show 技术分享 reference com student lap
原文地址:https://www.cnblogs.com/Black-rainbow/p/9168967.html