终于想起把之前的笔记整理成博客了,在笔记本被偷了之后一度以为之前的笔记也没了,后来又发现在云盘里发现了备份文件。所以整理了一下发出来。
创建数据库
create database gradem;
创建表
create table student
(sno char(10) not null primary key,
sname char(8),
ssex char(2),
sbirthday date,
saddress varchar(50),
sdept char (16),
speciality varchar(20),
constraint a1 check(ssex='男' or ssex='女')
);
create table course
(cno char(5) not null primary key,
cname varchar(20) not null
);
create table sc
(sno char(10) not null,
cno char(50) not null,
degree decimal(2,1),
constraint sc1 primary key(sno,cno),
);
create table teacher
(tno char(3) not null primary key,
tname varchar(20) not null,
tsex char(2),
tbirthday date,
tdept char (16),
constraint a1 check(ssex='男' or ssex='女')
);
create table teaching
(cno char(5) not null,
tno char(5) not null,
cterm tinyint(1),
constraint ct1 primary key(cno,tno)
);
修改表
alter table student add class char(10) after sname;
复制表
create table studbak select * from student;
查看student的存储结构
show status like 'student'\G;
查看student表的创建语句
show create table student;
创建一个指定存储引擎的表
create table s1
(sno char(10) primary key,
sname char(18)
)engine=memory;
删除表(删除标的结构和数据)
drop table student;
复制表
create table student1 select *from student;
插入数据
insert into student values
('20050201','刘晨','女','1998-06-04','山东青岛' ,'信息工程系','电子商务'),
('20050202','张丽','女','1998-08-25','河北唐山' ,'信息工程系','电子商务'),
('20050203','张立军',男'','1998-06-05','山东青岛' ,'信息工程系','电子商务'),
('20050204','汪敏','女','1998-12-23','江苏苏州' ,'数学系','数学');
删除数据(值删除数据)
delect from student;