关闭

超有用的sql查询语句。项目、面试都有用

标签: 面试javadatabasesql
697人阅读 评论(0) 收藏 举报
create database cstp;
use cstp;
/*1:建立学生表*/
create table student (
   学号 char(3) primary key,
   姓名 char(4),
   性别 char(2),
   年龄 int,
   班级 char(5)
);
insert into student values('108','曾华','男',19,'95033');
insert into student values('105','匡明','男',20,'95031');
insert into student values('107','王丽','女',20,'95033');
insert into student values('101','李军','男',19,'95033');
insert into student values('109','王芳','女',22,'95031');
insert into student values('103','陆君','男',20,'95031');
/*2:建立教师表*/
create table teacher(
   教师号 char(3) primary key,
   姓名 char(4),
   性别 char(2),
   年龄 int ,
   级别 char(6),
   专业 char(8)
);
insert into teacher values('804','李成','男',42,'副教授','计算机系');
insert into teacher values('856','张旭','男',35,'讲师','电子工程');
insert into teacher values('825','王萍','女',28,'助教','计算机系');
insert into teacher values('831','刘冰','女',25,'助教','电子工程');
/*3:建立课程表*/
create table course (
   课程号 char(5) primary key,
   课程名 char(10),
   教师号 char(3),
   foreign key(教师号) references teacher(教师号)
);
insert into course values('3-105','计算机导论','825');
insert into course values('3-245','操作系统','804');
insert into course values('6-166','数字电路','856');
insert into course values('9-888','高等数学','831');
/*4:建立选课表*/
create table sc(
   学号 char(3),
   课程号 char(5),
   primary key(学号,课程号),
   成绩 int,
   foreign key(学号) references student(学号),
   foreign key(课程号) references course(课程号)
);
insert into sc values('103','3-245',86);
insert into sc values('105','3-245',75);
insert into sc values('109','3-245',68);
insert into sc values('103','3-105',92);
insert into sc values('105','3-105',88);
insert into sc values('109','3-105',76);
insert into sc values('101','3-105',64);
insert into sc values('107','3-105',91);
insert into sc values('108','3-105',78);
insert into sc values('101','6-166',85);
insert into sc values('107','6-166',79);
insert into sc values('108','6-166',81);
/*5:所有表内容*/
select * from student;
select * from course;
select * from teacher;
select * from sc;
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:99460次
    • 积分:2978
    • 等级:
    • 排名:第11784名
    • 原创:208篇
    • 转载:14篇
    • 译文:0篇
    • 评论:5条
    最新评论