日期:2014-05-18  浏览次数:20672 次

求解.建表老是报错.
create table students
(stuId bigint identity(11111111,1) primary key,
stuName varchar(20) not null,
pwd varchar(20) not null)
go


create table classes
(classId varchar(8) primary key,
className varchar(20) not null,
semester varchar(20) not null)
go




create table grades
(stuId bigint identity(11111111,1) primary key,
stuName varchar(20) not null,
classId varchar(8) primary key,
className varchar(20) not null,
semester varchar(20) not null,
pscores int,
escores int,
foreign key grades(stuId) references classes(classId)
foreign key grades(classId) references classes(classId))
go


建第三个表老是提示说
消息 102,级别 15,状态 1,第 9 行
'grades' 附近有语法错误。
我楞是没看出哪错了.求解.

------解决方案--------------------
SQL code


create table grades
(stuId bigint identity(11111111,1) primary key,
stuName varchar(20) not null,
classId varchar(8) primary key,
className varchar(20) not null,
semester varchar(20) not null,
pscores int,
escores int,
foreign key classIdreferences classes(classId)--这样就好了
foreign key grades(classId) references classes(classId))
go

貌似你写的有错,应该是classId 的外键吧

------解决方案--------------------

create table grades
(stuId bigint identity(11111111,1) primary key,
stuName varchar(20) not null,
classId varchar(8) primary key,
className varchar(20) not null,
semester varchar(20) not null,
pscores int,
escores int,
foreign key (stuId) references classes(classId)--,
--foreign key (classId) references classes(classId))
go

不要前面的表名字,而且你这一个表怎么能有两个外键呢?
------解决方案--------------------
探讨
引用:
create table grades
(stuId bigint identity(11111111,1) primary key,
stuName varchar(20) not null,
classId varchar(8) primary key,
className varchar(20) not null,
semester varchar(20)……