Skip to content

Instantly share code, notes, and snippets.

@stormwild
Last active February 16, 2023 19:10
Show Gist options
  • Save stormwild/663c60e9a507f87f4ea6 to your computer and use it in GitHub Desktop.
Save stormwild/663c60e9a507f87f4ea6 to your computer and use it in GitHub Desktop.
Temporarily disable constraints on a table T-SQL, SQL Server
-- http://www.blackwasp.co.uk/SQLDisableConstraints.aspx
ALTER TABLE TableName NOCHECK CONSTRAINT ALL
ALTER TABLE TableName CHECK CONSTRAINT ALL
ALTER TABLE TableName NOCHECK CONSTRAINT FK_Table_RefTable
ALTER TABLE TableName CHECK CONSTRAINT FK_Table_RefTable
--http://stackoverflow.com/questions/253849/cannot-truncate-table-because-it-is-being-referenced-by-a-foreign-key-constraint
DELETE FROM TableName
DBCC CHECKIDENT ('TableName', RESEED, 0)
--http://stackoverflow.com/questions/253849/cannot-truncate-table-because-it-is-being-referenced-by-a-foreign-key-constraint
-- Below only applies to MySql
SET FOREIGN_KEY_CHECKS = 0; -- Disable foreign key checking.
TRUNCATE TABLE [YOUR TABLE];
SET FOREIGN_KEY_CHECKS = 1;
@bharat84
Copy link

select * from admin panel;

@lucasdanezine
Copy link

Thanks for sharing this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment