
create table xs(
Sno char(7) not null primary key,
Sname char(10) not null,
Ssex char(2),
Sage smallint,
Sdept char(20)
)
create table kc(
Cno char(6) primary key,
Cname char(20) not null,
Credit tinyint,
Semester tinyint
)
create table cj(
Sno char(7) not null,
Cno char(6) not null,
Grade tinyint
foreign key(Sno) references xs(Sno),
foreign key(Cno) references kc(Cno)
)
学生表 student
课程表 course
学生选课关系表 stucourse
create table student(sno number primary key,sname varchar2(20));
insert into student values(1,'alley');
insert into student values(2,'bob');
commit;
create table course(cno number primary key,cname varchar2(20));
insert into course values(1,'语文');
insert into course values(2,'数学');
commit;
create table stucourse(sno number,cno number);
alter table stucourse add constraint pk_stucource primary key(sno,cno);
insert into stucourse values(1,1);
insert into stucourse values(1,2);
insert into stucourse values(2,1);
commit;
2 select asname,ccname
from student a,stucourse b,course c
where asno = bsno and bcno=cno;
3 查询选修一门以上的学生,按学号从小到大排序
select asno, asname
from student a,stucourse b,course c
where asno = bsno and bcno=cno
group by asno,asname
having count(1)>=1
order by asno;
4、各用一条语句实现下列功能:添加表的列、更新表的某一字段值、删除表的列、删除表数据、修改表的名称。
alter table student add ssex varchar2(2);
update student set ssex='女';
alter table student drop column ssex;
delete from student where sno=1;
alter table student rename to studentnew;
5、在PL/SQL中执行SELECT语句:在某一实体表中,查询符合某一条件的记录,并显示相应的几个字段值
select sno, sname
from student
where sno=1;
6、用CASE语句实现一多分支结构
select case when sno=1 then '学号1‘ when sno=2 then '学号2' else '其他学号' end
from student;
以上就是关于怎样创建学生数据库用T-SQL语句全部的内容,包括:怎样创建学生数据库用T-SQL语句、Oracle创建学生选课数据库。完成下列要求:、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)