#创建表
create table if not exists student
(
id int primary key comment'学号',
studentName varchar(10) not null comment'姓名'
)comment'学生表';
#删除表
#DDL中删除表用的是drop而不是delete,delete是用在DML中的
drop table if exists student;
#选择表
alter table student
#++++++++++添加约束+++++++++++++
#添加主键约束
alter table student
add constraint pk_student primary key(id);
#添加外键约束
alter table emp
add constraint fk_emp_dept foreign key (DEPTNO) references dept(DEPTNO);
#添加唯一性约束
alter table student
add constraint uq unique(studentname)
#添加默认约束
alter table dept
change column LOC
LOC varchar(13) default 'beijing';
#添加非空约束
alter table dept
change column loc
loc varchar(13) not null;
MySQL系列——DDL语句
于 2022-04-09 20:02:22 首次发布