/*建库,名为student_info*/ create database student_info /*使用student_info*/ use student_info go /*建student表,其中s_id为主键*/ create table student ( s_id int identity(1,1) primary key, s_name varchar(20) not null, s_age int ) go /*建test表,其中test_no为主键*/ create table test ( test_no int identity(1,1) primary key, test_name varchar(30), nax_s int not null default(0), min_s int not null default(0) ) go /*建s表,其中s_id和test_no为外建,分别映射student表中的s_id和test表中的test_no*/ create table s ( s_id int not null, test_no int not null, s int not null default(0), primary key(s_id,test_no), foreign key(s_id) references student(s_id), foreign key(test_no) references test(test_no) ) go
联机丛书 计算列不能用作 DEFAULT 或 FOREIGN KEY 约束定义,也不能与 NOT NULL 约束定义一起使用。
create database student_info
/*使用student_info*/
use student_info
go
/*建student表,其中s_id为主键*/
create table student
(
s_id int identity(1,1) primary key,
s_name varchar(20) not null,
s_age int
)
go
/*建test表,其中test_no为主键*/
create table test
(
test_no int identity(1,1) primary key,
test_name varchar(30),
nax_s int not null default(0),
min_s int not null default(0)
)
go
/*建s表,其中s_id和test_no为外建,分别映射student表中的s_id和test表中的test_no*/
create table s
(
s_id int not null,
test_no int not null,
s int not null default(0),
primary key(s_id,test_no),
foreign key(s_id) references student(s_id),
foreign key(test_no) references test(test_no)
)
go
计算列不能用作 DEFAULT 或 FOREIGN KEY 约束定义,也不能与 NOT NULL 约束定义一起使用。
不能作外键的