立即学习:https://edu.csdn.net/course/play/27328/362528?utm_source=blogtoedu
create table contacts(
id int primary key,
name varchar(30),
phone varchar(11)
);
desc contacts;
alter table contacts add sex char(1);
alter table contacts drop column sex;
drop table contacts;
show tables;
3.
create table contacts(
id int not null auto_increment primary key,
name varchar(50),
sex tinyint default 1,
phone varchar(20)
);
insert into contacts(name,sex,phone) values('张三',1,'13968215111');
insert into contacts(name,sex,phone) values('Tom\'s cat',1,'13968215222');
insert into contacts(name,sex,phone) values("Lily's cat",1,'13968215333');
insert into contacts(name,sex,phone) values("李四",1,'13968215444'),('王五',1,'13968215555');
insert into contacts(name,phone) values("赵六",'13968215666');
update contacts set sex=2;
update contacts set sex=1;
update contacts set sex=2 where id=3;
update contacts set sex=2,phone='18900001111' where id=5;
delete from contacts where id=4;
delete from contacts ;
4、数据完整性(重点)
1、每张表的主键字段不能为空,不能重复。
2、域完整性:限制数据类型、检查约束、默认值、非空约束
3、参照完整性:外键约束
4、用户自定义完整性:规则、存储过程、触发器
5、唯一性约束:根据实际业务需要,比如身份证号唯一(外键:引用其他表主键)。
主键:
create table person(
id int not null auto_increment primary key comment '主键id',
name varchar(30) comment '姓名',
id_number varchar(18) unique comment '身份证号'
);
外键约束:
create table stu(
stu_no int not null primary key comment '学号',
stu_name varchar(30) comment '姓名'
);
create table sc(
id int not null auto_increment primary key comment '主键id',
stu_no int not null comment '学号',
course varchar(30) comment '课程',
grade int comment '成绩',
foreign key(stu_no) references stu(stu_no)
);