Click here to Skip to main content
16,019,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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')
Posted
Updated 8-Aug-11 1:30am
v4
Comments
[no name] 8-Aug-11 7:44am    
Is RACE_ID in Race_Master and is it set as the primary key?
maddykumfa 8-Aug-11 8:55am    
Yes Race_ID is the PK for Race_Master

1 solution

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?
 
Share this answer
 
Comments
maddykumfa 8-Aug-11 8:57am    
actually the user is aware that he is deleting that table.. it must be deleted and recreated..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900