学生表:Student (Sno, Sname, Ssex , Sage, Sdept)
学号,姓名,性别,年龄,所在系 Sno为主键
课程表:Course (Cno, Cname)
课程号,课程名 Cno为主键
学生选课表:SC (Sno, Cno, Score)
学号,课程号,成绩 Sno,Cno为主键
1.用SQL语句创建学生表student,定义主键,姓名不能重名,性别只能输入男或女,所在系的默认值是 “计算机”。
2.修改student 表中年龄(age)字段属性,数据类型由int 改变为smallint。
3.为SC表建立按学号(sno)和课程号(cno)组合的升序的主键索引,索引名为SC_INDEX 。
4.创建一视图 stu_info,查询全体学生的姓名,性别,课程名,成绩。
先进行选库
show databasses

选库----use chap06
创建表---create table student(
sno in primary key,
sname char(30)unique,
ssex char(1) check (ssex in ('F','N')),
sage int,
sdept char(20)
);
dese student

create table course (
cno int
cname char(20),
primary key(cno)
);
desc course

create table sc (
sno int,
cno int,
score int,
primary key(sno,cno)
);
desc sc

alter table student modify sage smallint;
desc student;

create index sc_index on sc (sno asc,cno asc);
show index from xs;
insert into student values (1,'xiaoming','M',18,'English')

insert into course valuse (1,'IT'),(2,'Engliash'),(3,'chinese'),(4,'math');

insert into sc valuse (1,2,80),(1,3,15),(2,1,10)(2,2,59);
select st.sname,st.ssex,co.cname,sc.score from student st.course co,sc