How to drop a list of SQL Server tables, ignoring constraints?

后端 未结 6 1186
醉梦人生
醉梦人生 2021-02-12 21:47

I have a list of half a dozen MSSQL 2008 tables that I would like to remove at once from my database. The data has been entirely migrated to new tables. There is no reference in

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-12 21:58

    A simple DROP TABLE dbo.MyTable will ignore all constraints (and triggers) except foreign keys (unless you drop the child/referencing table first) where you may have to drop these first.

    Edit: after comment:

    There is no automatic way. You'll have to iterate through sys.foreign_keys and generate some ALTER TABLE statements.

提交回复
热议问题