#使用数据库 use db_student1; #创建表,附带主键约束 create table student1 ( id int primary key, name Varchar(100), age int, high float, birthday date )charset utf8; #删除表 drop table student1; #查看表 desc student1; #在表里添加一列 alter table student1 add tz float; #在表里删除一列 alter table student1 drop tz; #将表里一列替换为另一列 alter table student1 change tz score int; alter table student1 add score int; alter table student1 drop score; #在表里插入数据 insert into student1 (id, name, age, high, birthday,tz,score) values (1,张三,18,175.5,2003-7-6,76,100); insert into student1 values (2,李四,28,165.5,2003-8-8,66,99); #修改表里的数据 update student1 set high 168 where id 1; #删除表里的数据 delete from student1 where id 2; #清空表里的数据 truncate table student1; #删除主键约束 alter table student1 drop primary key; #添加逐渐约束 alter table student1 add primary key(id); #创建表,附带主键自增约束 create table student2_tb ( id int primary key auto_increment, name Varchar(100), age int, high float, birthday date )charset utf8; #主键自增的特点:修饰的主键,除了非空唯一的特点外,额外可以自增 #注意:逐渐如果设置了自增,当设置了自增,不指定主键,或者指定主键后用0或null占位时自动增加1 insert into student2_tb (id, name, age, high, birthday) values (0,张三,18,165.5,2002-7-5); insert into student2_tb (name, age, high, birthday) values (李四,19,175.5,2003-7-3); truncate table student2_tb; #not null:非空,unique:唯一,default:设置默认值 create table student3_tb ( id int primary key auto_increment, name Varchar(100) not null , age int not null , class varchar(100) default AI, birthday date unique )charset utf8; insert into student3_tb (name, age, birthday) VALUE (张三,18,2020-7-6); #查看指定表的建表语句 show create table student3_tb; #查看所有的表 show tables; #更改表名 rename table student1 to student1_tb;