How to generate scripts to Re Generate Foreign Key Constraints in SQL Server Database - Part 73

preview_player
Показать описание
SQL Server / T-SQL Tutorial Scenario:
You need to truncate all the tables in SQL Server database, when when you run truncate statement, you get error below error.
Msg 4712, Level 16, State 1, Line 43
Cannot truncate table 'SchemaName.TableName' because it is being referenced by a FOREIGN KEY constraint.

The easy way would be drop the Foreign Key Constraints, truncate the tables and recreate the Foreign Key Constraint again.

Link to scripts used in SQL Server / TSQL Tutorial Video

Check out our website for Different SQL Server, MSBI tutorials and interview questions
such as SQL Server Reporting Services(SSRS) Tutorial
SQL Server Integration Services(SSIS) Tutorial
SQL Server DBA Tutorial
SQL Server / TSQL Tutorial ( Beginner to Advance)
Рекомендации по теме
Комментарии
Автор

Thanks Amir. I really need this drop and recreate fk in my assignment.. I was searching for solution last two days and stopped at your video.

venkatpinninti
Автор

For some reason, i dropped Fks i checked with isenabled query it said all are disabled but when i ran parent, reference query to check it showed it still exist. Can you help ?

mayurkharat