Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreign key

Status
Not open for further replies.

Carney123

Programmer
Apr 11, 2008
15
US
I need a script to enable Enforce relationship for INSERTs and UPDATES check box.

My foreign key is already established but this check box was unchecked, now I need to check this box using scripts. I need to send the script to client and also there are about 2000 tables involved.

Any help is appreciated.
 
This is the script that was Auto-generated by SSMS when I added CASCADE for UPDATE and DELETE in Relationship
Code:
/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE HumanResources.EmployeeDepartmentHistory
	DROP CONSTRAINT FK_EmployeeDepartmentHistory_Department_DepartmentID
GO
ALTER TABLE HumanResources.Department SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE HumanResources.EmployeeDepartmentHistory ADD CONSTRAINT
	FK_EmployeeDepartmentHistory_Department_DepartmentID FOREIGN KEY
	(
	DepartmentID
	) REFERENCES HumanResources.Department
	(
	DepartmentID
	) ON UPDATE  CASCADE 
	 ON DELETE  CASCADE 
	
GO
DECLARE @v sql_variant 
SET @v = N'Foreign key constraint referencing Department.DepartmentID.'
EXECUTE sp_addextendedproperty N'MS_Description', @v, N'SCHEMA', N'HumanResources', N'TABLE', N'EmployeeDepartmentHistory', N'CONSTRAINT', N'FK_EmployeeDepartmentHistory_Department_DepartmentID'
GO
ALTER TABLE HumanResources.EmployeeDepartmentHistory SET (LOCK_ESCALATION = TABLE)
GO
COMMIT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top