Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Verification if a primary key exists
Message
 
 
To
04/03/2008 15:01:35
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01298604
Message ID:
01298608
Views:
24
This message has been marked as a message which has helped to the initial question of the thread.
>I have some code that are removing a primary key from all my tables. However, if this primary key does not exist, this will stop the script once reached. I need to verify if the primary key exists first before attempting to remove it. I have this presently:
>
>
>ALTER TABLE [MyTable] DROP CONSTRAINT Numero
>
Try

USE
SELECT Table_Name as [Table], Column_Name as [Column],
Constraint_Name as [Constraint], Table_Schema as [Schema]
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
ORDER BY [Table], [Column]
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform