多表查詢建表語句

2021-10-09 23:53:25 字數 3945 閱讀 6253

–1.學生表

student(s_id,s_name,s_birth,s_***) –學生編號,學生姓名, 出生年月,學生性別

–2.課程表

course(c_id,c_name,t_id) – –課程編號, 課程名稱, 教師編號

–3.教師表

teacher(t_id,t_name) –教師編號,教師姓名

–4.成績表

score(s_id,c_id,s_score) –學生編號,課程編號,分數

–建表–學生表

create

table

`student`

(`s_id`

varchar(20

),`s_name`

varchar(20

)not

null

default'',

`s_birth`

varchar(20

)not

null

default'',

`s_***`

varchar(10

)not

null

default'',

primary

key(

`s_id`))

;--課程表

create

table

`course`

(`c_id`

varchar(20

),`c_name`

varchar(20

)not

null

default'',

`t_id`

varchar(20

)not

null

,primary

key(

`c_id`))

;--教師表

create

table

`teacher`

(`t_id`

varchar(20

),`t_name`

varchar(20

)not

null

default'',

primary

key(

`t_id`))

;--成績表

create

table

`score`

(`s_id`

varchar(20

),`c_id`

varchar(20

),`s_score`

int(3)

,primary

key(

`s_id`

,`c_id`))

;--插入學生表測試資料

insert

into student values

('01'

,'趙雷'

,'1990-01-01'

,'男');

insert

into student values

('02'

,'錢電'

,'1990-12-21'

,'男');

insert

into student values

('03'

,'孫風'

,'1990-05-20'

,'男');

insert

into student values

('04'

,'李雲'

,'1990-08-06'

,'男');

insert

into student values

('05'

,'周梅'

,'1991-12-01'

,'女');

insert

into student values

('06'

,'吳蘭'

,'1992-03-01'

,'女');

insert

into student values

('07'

,'鄭竹'

,'1989-07-01'

,'女');

insert

into student values

('08'

,'王菊'

,'1990-01-20'

,'女');

--課程表測試資料

insert

into course values

('01'

,'語文'

,'02');

insert

into course values

('02'

,'數學'

,'01');

insert

into course values

('03'

,'英語'

,'03');

--教師表測試資料

insert

into teacher values

('01'

,'張三');

insert

into teacher values

('02'

,'李四');

insert

into teacher values

('03'

,'王五');

--成績表測試資料

insert

into score values

('01'

,'01',80

);insert

into score values

('01'

,'02',90

);insert

into score values

('01'

,'03',99

);insert

into score values

('02'

,'01',70

);insert

into score values

('02'

,'02',60

);insert

into score values

('02'

,'03',80

);insert

into score values

('03'

,'01',80

);insert

into score values

('03'

,'02',80

);insert

into score values

('03'

,'03',80

);insert

into score values

('04'

,'01',50

);insert

into score values

('04'

,'02',30

);insert

into score values

('04'

,'03',20

);insert

into score values

('05'

,'01',76

);insert

into score values

('05'

,'02',87

);insert

into score values

('06'

,'01',31

);insert

into score values

('06'

,'03',34

);insert

into score values

('07'

,'02',89

);insert

into score values

('07'

,'03',98

);

mysql建表語句

在sql語句中注意 約束的概念 1.實體完整性約束 主鍵 唯一且非空 primary key 違約處理 no action 拒絕執行 2.參照完整性約束 外來鍵約束 foregin key references tablename filedname on delete update casecad...

mysql建表語句

mysql裝好以後,進入命令列,開始建表需要先建立乙個database.開始使用 create database mybase use mybase create table user id int 10 auto increment not null primary key,username va...

mysql建表語句

工作的時候總會寫一些建表語句提交給db,有的時候就會忘記主鍵自增寫法,以及一些型別的標註,下面是乙個比較全的建表語句,包括各種型別。create table minisite lock site id int not null auto increment primary key,admin id ...