For adding Constraints _ UNIQUE NONCLUSTERED

Posted by srilakshmi15-4307 under Sql Server on 1/20/2012 | Points: 10 | Views : 1685 | Status : [Member] | Replies : 0
GO
/****** Object: Index [ConstrName] Script Date: 12/10/2011 17:05:59 ******/

IF NOT EXISTS (Select * From Sys.Objects Where Object_ID = Object_ID('ConstrName') AND Type ='UQ')
BEGIN
ALTER TABLE [dbo].[TableName] ADD CONSTRAINT ConstrName UNIQUE NONCLUSTERED
(
[Col1] ASC,
[Col2] ASC
)WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
END

GO


GO
IF NOT EXISTS (Select * From Sys.Objects Where Object_ID = Object_ID('FK_ConstrName') AND Type ='F')
BEGIN
ALTER TABLE [dbo].[TableName1] WITH CHECK ADD CONSTRAINT [FK_ConstrName] FOREIGN KEY([Col])
REFERENCES [dbo].[TableName2] ([Col])
END
GO




Responses

(No response found.)

Login to post response