#创建表(eg:student)
mysql> create table student
-> (
-> id int not null,
-> name varchar(45),
-> age int not null,
-> pwd varchar(45) not null,
-> primary key(id)
-> );
查看student 的表结构
desc student
更新数据库表的结构
alter table student add major varchar(20)
更新表的定义,给表加上一列使用
alter table student drop column age
删除表中的一列,用到关键字column
alter table student modify 字段名称 字段类型【是否非空】
修改表属性类型;(*)
delete from student
删除表中所有内容(法:1)
truncate table student
删除表中所有内容(法:2)
drop table student
删除表
delete from student where id = x
删除表的一条记录
alter table student change<字段名><字段新名称><字段的类型>
**[新增命令]**修改字段的名称
往往在网站进行重构时,通常会进行数据结构的修改。
#批量增加字
#可以使用事务
begin; #事务开始
alter table 表名 add 字段名 字段类型(长度);
alter table 表名 add 字段名 字段类型(长度);
alter table 表名 add 字段名 字段类型(长度);
alter table 表名 add 字段名 字段类型(长度);
commit;
#或者
alter table 表名 add (字段1 类型(长度),字段2 类型(长度),字段3 类型(长度));
增(插入语句)
insert into student(id,name,pwd,major) values (1,‘chulan’,‘12345’ ,‘computer’)