0

I've been trying to fix this problem for hours now and I have no idea what causes it. I'm trying to drop tables in MSSQL Server (I need to start from scratch) and whenever I'm using the statement

DROP TABLE dbo.Manages;

I get this message:

Could not drop object 'dbo.Manages' because it is referenced by a FOREIGN KEY constraint.

Problem is, I have three tables left and all of them contain foreign keys(they're linked with eachother). It turned out that I can't delete either and I'm stuck. I tried dropping foreign keys first, but

ALTER TABLE dbo.Manages DROP FOREIGN KEY Mgr_start_date;

wouldn't work. I know there's also a way to write it like this:

ALTER TABLE dbo.Manages
DROP FOREIGN KEY fk_(...)

Yet when I created the foreign keys, I didn't use fk_, I just simply stated

ALTER TABLE dbo.Department
    ADD FOREIGN KEY (Mgr_start_date)
    REFERENCES dbo.Manages(Mgr_start_date);

Any help would be highly appreciated. I'm fairly new to SQL, but I really want to make this work. I tried some solutions from this forum like using FOREIGN_KEY_CHECKS = 0 and then setting it to 1, but it wouldn't work either.

Darwin von Corax
  • 5,201
  • 3
  • 17
  • 28
Jake
  • 67
  • 3
  • 10

2 Answers2

1

You can use the GUI to delete the foreign keys. In Management studio on the table folders you find your foreign keys in the Key folder. Or use EXEC sp_fkeys 'Your Table' to find the names of your foreign keys.

Cramaboule
  • 13
  • 1
  • 6
0

Actually, I think I finally succeeded. I right-clicked on my specific database and chose 'design', then found the names of the foreign keys in drop down menu under properties. That way I was able to find the names of foreign keys that the program has set, and drop them normally. Works just fine, database was cleaned up. Thank you very much for your suggestions!

Jake
  • 67
  • 3
  • 10