外键管理
外键作用:用来给字段加约束
创建外键
方式1:创表时增加外键
create table 表名(
........
constraint 外键名 foreign key (外键字段名) references 主键表名(主键字段名)
)
方式2:创完表后修改
create table 表名(
........
)alter table 表名 add constraint 外键名 foreign key (外键字段名) references 主键表名(主键字段名)
删除外键:先删子表,再删主表
删除外键、删除表
alter table 表名 drop foreign 外键名;
alter table 表名 drop index 外键名;------必须删除索引
DML语言
用于操作数据库对象中所包含的数据
包括:
insert(添加数据语句)
insert into 表名 (字段1,字段2,.........) values(值1,值2,.........)
update(更新(或修改)数据语句)
update 表名 set 字段名=值,........... where 条件语句;
delete(删除数据语句)
delete from 表名 [where 条件语句];
truncate [table] 表名;---------用于清空表数据,但表结构、索引、约束等不变