1.DDL
数据定义语言
针对数据库进行操作的sql语句
查看有哪些数据库?
show databases;
创建数据库?
create database db1;
查看创建数据库的细节?
show create database db1;
删除数据库?
drop database db1;
使用具体的数据库?
use db1;
针对表结构进行操作的sql语句
查看有哪些表的?
show tables;
查看表结构的?
desc user;
查看表的创建细节?
show create table user;
创建表?
create table user (
id int,
name varchar(20)
);
给user表增加一条字段?
alter table user add gender varchar(20);
给gender字段修改名字叫sex?
alter table user change gender sex varchar(20);
给sex字段修改数据类型?
alter table user mofidy sex int;
删除字段?
alter table user drop sex;
给表改名字?
rename table user to person;
删除表?
drop table user;
删除表后再重新创建该表?
truncate table user;
2.DML
数据操作语言
增
insert into user (name) values('张三');
insert into user (id, name) values(1, '张三');
insert into user values(1, '张三');
删
delete from user where id = 1;
delete from user where name = '张三';
delete from user;
改
update user set name='赵四' where id = 1;
update user set id = 2 where name='张三';
3.DQL*
数据查询语言
简单的单表查
select * from user;
select id from user;
select name, id from user;
sql的书写顺序:
S(select)..F(from)…W(where)…G(group by)…H(having)…O(order by)…L(limit)
|
|