Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
SQL
USE [MYDATABASE]
GO

select * from sys.objects

GO


I ran this query above to get all object in my DB, then I found a table that is giving me troubles.

I want to delete this table in sys.objects using object_id

SQL
USE [MYDATABASE]
GO

DELETE FROM sys.objects
      WHERE object_id=245575913 
GO</pre>


but I get error:

SQL
Msg 259, Level 16, State 1, Line 2
Ad hoc updates to system catalogs are not allowed.



The problem started when I was generating a database from a model in EF, I deleted the table manually and it disappeared. But when I tried to generate the database from model again it gave me an error that leads me to that table and some foreign keys. So thats thats were I decided to search the sys.objects


How can I remove this table?
Posted

You cannot update the system catalogs directly. To remove an object from the sys.objects catalog, drop the object:
SQL
DROP TABLE TheTableToDrop
 
Share this answer
 
Comments
Anele Ngqandu 18-Mar-15 12:19pm    
Restarted my pc the table is gone but still couldn't create DB from model so just decided to just drop the dam DB
If you check the sys.objects table you will see that one of the columns has the type name. For example, CHECK_CONSTRAINT. You can then call: DROP CONSTRAINT [NAME] You can drop or change it according to the type description.

Good luck!
 
Share this answer
 
v2

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