SQL-DDL语言
- Create,创建表结构
create table TABLENAME
(
col1 dataType [not null],
col2 dataType [not null],
col3 dataType [not null],
col4 dataType [not null],
col5 dataType [not null],
col6 dataType [not null],
.....
)
示例:
- alter和drop,修改和删除表的机构
-- 增加表的字段
alter table tname add(col1 datatype)
-- 删除表字段
alter table tname drop column colName
-- 修改字段名称
alter table tname rename column to newName
-- 修改字段的数据类型
alter table tname modify column dataType
-- 修改表名
rename oldTname to newName
-- 删除表结构
drop table tname
-- 查看表结构
desc tname
- Truncate:清空表中所有数据
-- 清空表中所有数据
truncate table tname;
DML语言
- insert:向表中插入记录
-- 插入记录
insert into tname(col1,col2...) values(val1,val2....)
列名可省略,但是其后的值必须一一对应
- delete:删除记录
-- 删除表中所有记录(可回滚)
delete [from] tname;
-- 删除指定条件的数据
delete [from] tname where 条件
- update:用来更新数据
update tname set col1=val1[,col2=val2] [where 条件]
DQL语言
select :查询数据(必须基于一张表)
需日后多加练习。
相关材料: