Some basic query statements in SQL Server

Source: Internet
Author: User
Tags x2 y2

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'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.