The Internet to find sql statement to delete a database to get all foreign key constraints statements
But found that it was just an inquiry, to be performed, then had to copy out the execution, more trouble
So wrote a sp to automate more convenient
code show as below:
- CREATE PROCEDURE sp_drop_all_fk
- as
- declare @sql varchar(255)
- declare dropsql_cursor cursor for
- select 'alter table '+object_name(fkeyid)+' drop constraint '+object_name(constid)+char(10) from sysreferences
- open dropsql_cursor
- fetch dropsql_cursor into @sql
- begin tran
- while @@fetch_status=0
- begin
- execute(@sql)
- if @@error <> 0
- begin
- rollback
- return
- end
- fetch dropsql_cursor into @sql
- end
- deallocate dropsql_cursor
- commit
- GO
Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2012/12/05/2802522.html