-- 创建表
create table t_student(
id int(8) PRIMARY KEY,
grade int(8) not null,
address varchar(200) not null UNIQUE
);
-- 删除表
drop table t_student;
-- 在表中添加一个新字段
alter table t_person add grade int(8) DEFAULT 0;
-- 查看表结构
DESC t_person;
-- 修改一个字段
alter table t_person CHANGE sname name varchar(200) not NULL;
-- 修改表名
RENAME table t_person to t_student;
-- 全字段插入
select * from t_student;
INSERT into t_student values(1,'zhangsan','男',80);
-- 选择几个字段插入
insert into t_student (id,name) VALUES (2,'lisi');
-- 一次性插入多行
insert into t_student (id,name) values (3,'lj'),(4,'po'),(5,'qw');
-- 给某个字段添加自增
alter table t_student modify id int(8) auto_increment;
desc t_student;
insert into t_student values (0,'wb','女',90);
-- 修改id=5的name为shanghai
update t_student set name='shanghai' where id=5;
-- 删除表中所有数据
delete from t_student;
-- 删除表中name为shanghai的数据
delete from t_student where name='shanghai';
-- 备份数据库
mysqldump -uroot -p t_student > d:/db_test.sql
SQL语法之DDL
最新推荐文章于 2022-05-11 21:50:52 发布