February 10, 2010 at 5:40 pm
Comments posted to this topic are about the item Changing Primary key names to standard naming convention across the DB
March 1, 2010 at 2:16 pm
This could also be done simply using the INFORMATION_SCHEMA.TABLE_CONSTRAINTS view.
SELECT 'EXEC sp_rename ''[' + c.CONSTRAINT_SCHEMA + '].[' + c.CONSTRAINT_NAME + ']'', ' +
'''PK_' + c.TABLE_NAME + ''', ''OBJECT'' '
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
WHERE c.CONSTRAINT_TYPE = 'PRIMARY KEY'
AND c.TABLE_NAME IS NOT NULL
ORDER BY c.TABLE_NAME
March 2, 2010 at 9:40 pm
Yes !! this query is much simpler !! 🙂
July 29, 2011 at 8:28 am
I don't see the point.... if that's the 'standard' then the DB should have been developed that way to begin with. If the DB has had any code written against it, this will likely break a lot of it.... just saying...
September 29, 2014 at 3:42 am
I would add "WHERE ....... and '['+b.name+']'<>'[PK_'+a.name+']'" because my server likes to be lazy.
May 12, 2016 at 7:33 am
Thanks for the script.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply