使用T-SQL语句按下表结构创建表(在创建表时定义约束)

2024-11-17 05:53:51
推荐回答(5个)
回答1:

create table grade
(
StudentNum char(9) not null primary key,
CourseID int not null unique,
DailyGrade decimal(5,1) check(decimal>=0 and decimal<=20),
PracticeGrade decimal(5,1) check(PracticeGrade>=0 and PracticeGrade<=30),
TestGrade decimal(5,1) check(TestGrade>=0 and TestGrade<=50)
)

对于总评,我不明白你的意思!
还有一点请注意,在一个表里只能创建一个主键,而你的题目出现两个主键,明显是错的,因此我把课程号设为唯一键!

回答2:

create
table
Grade
(StudentNum
char(9)
not
null,
CourseID
int
not
null,
primary
key(StudentNum,CourseID),
DailyGrade
decimal(5,1)
check(DailyGrade>=0
and
DailyGrade<=20),
PracticeGrade
decimal(5,1)
check(PracticeGrade>=0
and
PracticeGrade<=30),
TestGrade
decimal(5,1)
check(TestGrade>=0
and
TestGrade<=50),
Grade
as
isnull(DailyGrade,0)*0.2+isnull(PracticeGrade,0)*0.3+isnull(TestGrade,0)*0.5
)

回答3:

create table Grade
(StudentNum char(9) not null,
CourseID int not null,
primary key(StudentNum,CourseID),
DailyGrade decimal(5,1) check(DailyGrade>=0 and DailyGrade<=20),
PracticeGrade decimal(5,1) check(PracticeGrade>=0 and PracticeGrade<=30),
TestGrade decimal(5,1) check(TestGrade>=0 and TestGrade<=50),
Grade as isnull(DailyGrade,0)*0.2+isnull(PracticeGrade,0)*0.3+isnull(TestGrade,0)*0.5
)

回答4:

create
table
grade
(
StudentNum
char(9)
not
null
primary
key,
CourseID
int
not
null
unique,
DailyGrade
decimal(5,1)
check(decimal>=0
and
decimal<=20),
PracticeGrade
decimal(5,1)
check(PracticeGrade>=0
and
PracticeGrade<=30),
TestGrade
decimal(5,1)
check(TestGrade>=0
and
TestGrade<=50)
)
对于总评,我不明白你的意思!
还有一点请注意,在一个表里只能创建一个主键,而你的题目出现两个主键,明显是错的,因此我把课程号设为唯一键!

回答5:

Grade 总评 由平时成绩(20%)、实践成绩(30%)和期末成绩(50%)计算而来
这一句怎么搞呀?????