四、表约束
  1.定义主键约束:
  create table demo1(
  id int primary key,
  name varchar(40)
  );
  2.插入空id:
  insert into demo1(name) values('aaa');/*报错,主键不能为空*/
  3.插入重复的id:
  insert into demo1(id,name) values(1,'aaa');
  /*报错,主键不能重复*/
  insert into demo1(id,name) values(1,'aaa');
  4.显定义主键自动增长(auto_increment):
  create table demo2(
  id int auto_increment primary key,
  name varchar(40)
  );
  5.定义约束(unique):
  create table demo3(
  id int auto_increment primary key,
  name varchar(40) unique /*unique:约束*/
  );
  6.定义非空(not null):
  create table demo4(
  id int auto_increment primary key,
  name varchar(40) not null
  );
  7.定义外键约束():
  create table department(
  id int auto_increment primary key,
  name varchar(30) not null
  );
  create table employee2(
  id int auto_increment primary key,
  name varchar(30) not null,
  salary  double,
  department_id int,
  /*外键约束*/
  constraint department_id_FK foreign key(department_id) references department(id)
  );
  6.定义非空(not null):
  create table demo4(
  id int auto_increment primary key,
  name varchar(40) not null
  );
  7.删除主键:
  alter table tablename drop primary key;