I can get the code of a stored procedure using the syscomments table.
select so.name, sc.text as storedproccode
from sysobjects so (nolock)
inner join syscomments sc (nolock) on sc.id = so.id
where so.name = 'tablename'
How can I get the code for a specific foreign key constraint? I have the foreign key name.
Let me clarify what I’m looking for.
I find my table in the Object Explorer and expand the list of keys. If there is a primary key I can then right click on the primary key constraint and bring up the script in a new window.
The code looks like this:
USE [Gemini]
GO
/****** Object: Index [PK_CM_FULFILLMENT_HISTORY] Script Date: 02/17/2012 16:50:23 ******/
ALTER TABLE [dbo].[CM_FULFILLMENT_HISTORY] ADD CONSTRAINT [PK_CM_FULFILLMENT_HISTORY] PRIMARY KEY NONCLUSTERED
(
[pan] ASC,
[RequestCode] ASC,
[RequestDate] ASC
)WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [GEMINI_12_Indx_FG]
I can also do this with foreign key constraints.
Is there any way to retrive the code (script) of these constraints?
Thanks
I found a script that does the trick.