Create Database data1
Use data1
Create Table T1
(
X1 int,
Y1 varchar (20)
)
Create Table T2
(
X2 int,
Y2 varchar (20)
)
Insert into T1
Values (1, 'lala ')
Insert into T1
Values (2, 'hahaha ')
Insert into T2
Values (10, 'feifei ')
Insert into T2
Values (20, 'popo ')
Insert into T2
Values (30, 'bobobo ')
Select * from T1
Select * From T2
Select * from T1, T2
X1 Y1 X2 Y2
1 Lala 10 Feifei
2 Haha 10 Feifei
1 Lala 20 Popo
2 Haha 20 Popo
1 Lala 30 Bobo
2 Haha 30 Bobo
Create Table student
(
Student ID int primary key,
Name varchar (20 ),
Gender char (2 ),
Age int,
Department varchar (30)
)
Insert into student
Values (1001, 'andy Lau ', 'male', 40, 'computer ')
Insert into student
Values (1002, 'zhou jile', 'male', 30, 'Chinese ')
Insert into student
Values (1003, 'Chapter ziyi', 'female ', 28, 'mat ')
Insert into student
Values (1004, 'lin xinru ', 'female', 25, 'China ')
Create Table Course
(
Course No. Int primary key,
Course name varchar (20 ),
Credit int
)
Insert into course
Values (1, 'database', 4)
Insert into course
Values (2, 'mates', 5)
Insert into course
Values (3, 'ancient China', 3)
Create Table electives
(
Student ID int foreign key (student ID) References student (student ID)
On Delete Cascade
On update cascade,
Course No. Int foreign key (course No.) References course (course No)
On Delete Cascade
On update cascade,
Score int
)
Insert into electives
Values (1001,1, 92)
Insert into electives
Values (1001,2, 85)
Insert into electives
Values (1001,3, 88)
Insert into electives
Values (1002,2, 90)
Insert into electives
Values (1004,3, 92)
Insert into electives
Values (1002,3, 80)
Select * from student
Select * from course
Select * From electives
Select electives. Student ID, name, score from student, course, select where student. Student ID = electives. Student ID and course. Course number = electives. Course number and Course name = 'mat'
Select * from student, course, select where student. Student ID = electives. Student ID and electives. Course number = course. Course number and Course name = 'mat'