谁能帮我找一下这组sql语句的错误所在?CREATE DEFAULT Sage AS 18goCREATE DEFAULT Grade AS 60goCREATE DEFAULT Ssex AS '男'goCREATE RULE Ssex AS @col IN ('男', '女')goCREATE RULE Grade AS @col BETWEEN 0 AND 100goCREATE RULE Sage AS @col
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 16:45:16
谁能帮我找一下这组sql语句的错误所在?CREATE DEFAULT Sage AS 18goCREATE DEFAULT Grade AS 60goCREATE DEFAULT Ssex AS '男'goCREATE RULE Ssex AS @col IN ('男', '女')goCREATE RULE Grade AS @col BETWEEN 0 AND 100goCREATE RULE Sage AS @col
谁能帮我找一下这组sql语句的错误所在?
CREATE DEFAULT Sage
AS 18
go
CREATE DEFAULT Grade
AS 60
go
CREATE DEFAULT Ssex
AS '男'
go
CREATE RULE Ssex
AS @col IN ('男', '女')
go
CREATE RULE Grade
AS @col BETWEEN 0 AND 100
go
CREATE RULE Sage
AS @col BETWEEN 0 AND 150
go
CREATE TABLE Course
(
Cno integer NOT NULL ,
Cname varchar(20) NULL ,
Cpno smallint NULL ,
Ccredit smallint NULL
)
go
ALTER TABLE Course
ADD CONSTRAINT XPKCourse PRIMARY KEY CLUSTERED (Cno ASC)
go
CREATE TABLE SC
(
Sno varchar(20) NOT NULL ,
Cno integer NOT NULL ,
Grade smallint NULL
)
go
ALTER TABLE SC
ADD CONSTRAINT XPKSC PRIMARY KEY CLUSTERED (Sno ASC,Cno ASC)
go
exec sp_bindefault 'Grade', 'SC.Grade'
go
CREATE TABLE Student
(
Sno varchar(20) NOT NULL ,
Sname varchar(20) NULL ,
Ssex varchar(20) NULL ,
Sage smallint NULL ,
Sdept varchar(20) NULL
)
go
ALTER TABLE Student
ADD CONSTRAINT XPKStudent PRIMARY KEY CLUSTERED (Sno ASC)
go
exec sp_bindefault 'Ssex', 'Student.Ssex'
go
exec sp_bindefault 'Sage', 'Student.Sage'
go
ALTER TABLE SC
ADD CONSTRAINT R_1 FOREIGN KEY (Sno) REFERENCES Student(Sno)
ON DELETE NO ACTION
ON UPDATE NO ACTION
go
ALTER TABLE SC
ADD CONSTRAINT R_3 FOREIGN KEY (Cno) REFERENCES Course(Cno)
ON DELETE NO ACTION
ON UPDATE NO ACTION
go
exec sp_bindrule 'Grade', 'SC.Grade'
go
exec sp_bindrule 'Ssex', 'Student.Ssex'
go
exec sp_bindrule 'Sage', 'Student.Sage'
go
错误显示:
消息 2714,级别 16,状态 3,过程 Sage,第 2 行
数据库中已存在名为 'Sage' 的对象.
消息 2714,级别 16,状态 3,过程 Grade,第 3 行
数据库中已存在名为 'Grade' 的对象.
消息 2714,级别 16,状态 3,过程 Ssex,第 3 行
数据库中已存在名为 'Ssex' 的对象.
消息 2714,级别 16,状态 3,过程 Ssex,第 3 行
数据库中已存在名为 'Ssex' 的对象.
消息 2714,级别 16,状态 3,过程 Grade,第 3 行
数据库中已存在名为 'Grade' 的对象.
消息 2714,级别 16,状态 3,过程 Sage,第 3 行
数据库中已存在名为 'Sage' 的对象.
消息 15016,级别 16,状态 1,过程 sp_bindefault,第 103 行
默认值 'Grade' 不存在.
消息 15016,级别 16,状态 1,过程 sp_bindefault,第 103 行
默认值 'Ssex' 不存在.
消息 15016,级别 16,状态 1,过程 sp_bindefault,第 103 行
默认值 'Sage' 不存在.
已将规则绑定到表的列.
已将规则绑定到表的列.
已将规则绑定到表的列.
貌似不是,这组sql是ERWIn自动生成的,可以生成三个表,但是有错误,错误在默认值和约束条件
谁能帮我找一下这组sql语句的错误所在?CREATE DEFAULT Sage AS 18goCREATE DEFAULT Grade AS 60goCREATE DEFAULT Ssex AS '男'goCREATE RULE Ssex AS @col IN ('男', '女')goCREATE RULE Grade AS @col BETWEEN 0 AND 100goCREATE RULE Sage AS @col
这个脚本你已经运行了一遍了,所以里面有些对象已经生成了.SQL语句一般要这样写:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Notice]') and OBJECTPROPERTY(id,N'IsUserTable') = 1)
drop table [dbo].[Notice]
GO
当你要生成一个对象的时候,要先判断是不是存在,存在的话就先删除,然后再创建.