I have two tables:
CREATE TABLE dbo.country
(
cntry_id VARCHAR(2) NOT NULL,
name VARCHAR(50) NOT NULL,
CONSTRAINT pk_country PRIMARY KEY (cntry_id)
CREATE TABLE dbo.city
(
city_id VARCHAR(3) NOT NULL,
name VARCHAR(50) NOT NULL,
cntry_id VARCHAR(2) NOT NULL,
CONSTRAINT pk_city PRIMARY KEY (city_id),
FOREIGN KEY (cntry_id) REFERENCES dbo.country(cntry_id)
)
I am trying to drop the fk constrait so I can then drop the table.
The FK definitley exists:
EXEC sp_fkeys country
pktable_qualifier pktable_owner pk_tablename ...
xxxxxx xxx country cntry_id ....
(DB name obscured)
But both
EXEC sp_dropkey foreign, country, city
EXEC sp_dropkey foreign, city, country
return
264 Error (17499) No foreign key for the table or view exists. sp_dropkey(263)
Does anybody know how to drop these keys?
Thank you in advance
Ryan
Otherwise I don’t know what could be the reason. The number of the error message means he couldn’t delete it from syskeys. But he found the two tables alright and your are the owner of the tables too.
Did you try
sp_helpkeyandsp_helpconstraintto check what they say about the existence of a FK?This should also be able to tell you if there really is a FK defined.
Regarding the naming of a FK. This should do the trick