Skip to content
Advertisement

Finding a Primary Key Constraint on the fly in SQL Server 2005

I have the following SQL:

Since I have multiple environments, that PK_PS_userVariables constraint name is different on my different databases. How do I write a script that gets that name then adds it into my script?

Advertisement

Answer

While the typical best practice is to always explicitly name your constraints, you can get them dynamically from the catalog views:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement