Home > Handy Scripts > Generic “ENABLE ALL FKs”

Generic “ENABLE ALL FKs”

SELECT 'ALTER TABLE ' + QUOTENAME(LTRIM(RTRIM([TABLE_SCHEMA]))) + '.' + QUOTENAME(LTRIM(RTRIM([TABLE_NAME]))) + ' WITH CHECK CHECK CONSTRAINT ALL' 
FROM [INFORMATION_SCHEMA].[TABLES] 
WHERE OBJECTPROPERTY(OBJECT_ID(QUOTENAME(LTRIM(RTRIM([TABLE_SCHEMA]))) + '.' + QUOTENAME(LTRIM(RTRIM([TABLE_NAME])))), 'IsMSShipped') = 0 
	  AND [TABLE_TYPE] = 'BASE TABLE';

 

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: