运行脚本时出现SQL错误 [英] SQL Error While running Script

查看:100
本文介绍了运行脚本时出现SQL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过运行此脚本,我正在得知RACE_ID不存在错误,请让我知道这有什么问题...
注意:数据库中存在一个不包含Race_ID列的"Easternity_Master"表

Im Getting That RACE_ID does''nt Exist Error by running this script please let me know whats wrong in this...
Note: There is a table Ethnicity_Master without the Race_ID column exists in the Database

if exists(select * from Sysobjects
where Xtype=''U'' and ltrim(rtrim(Name))=''Ethnicity_Master'')
begin 
drop table Ethnicity_Master
CREATE TABLE Ethnicity_Master
(
Ethnicity_ID int primary key identity (1,1) not null, 
Race_ID  int ,
Ethnicity_Description nvarchar(500),
foreign key (Race_ID) references Race_Master(Race_ID) on delete cascade
)
end
else
Begin
CREATE TABLE Ethnicity_Master
(
Ethnicity_ID int primary key identity (1,1) not null, 
Race_ID  int ,
Ethnicity_Description nvarchar(500),
foreign key (Race_ID) references Race_Master(Race_ID) on delete cascade
)
End
insert into Ethnicity_Master(Race_ID,Ethnicity_Description) values(1,''European'')
insert into Ethnicity_Master(Race_ID,Ethnicity_Description) values(1,''Armenian'')
insert into Ethnicity_Master(Race_ID,Ethnicity_Description) values(1,''English'')

推荐答案

首先,您的Race_Master表似乎没有Race_ID列(检查拼写错误).

其次,在创建表之前删除表不是一个好主意,您可以仅显示一条消息,指出该表已存在,而不是删除该表然后再重新创建它.如果您的表有数百万行,并且有人错误地执行了该脚本怎么办?
First, it seems your Race_Master table doesn''t have a Race_ID column (check for misspelling).

Second, it is not a good idea to drop a table before creating it, you could just show a message that the table already exists instead of dropping it and then recreating it. What if your table has millions of rows and someone executes this script by mistake?


这篇关于运行脚本时出现SQL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆