From: Muhammad Bilal on 27 Apr 2010 11:39 Hi. I want to remove the primary key on table on any column if exists otherwise do nothing. Regards, Muhammad Bilal
From: Erland Sommarskog on 27 Apr 2010 18:22 Muhammad Bilal (MuhammadBilal(a)discussions.microsoft.com) writes: > I want to remove the primary key on table on any column if exists > otherwise do nothing. SELECT 'ALTER TABLE ' + quotename(p.name) + ' DROP CONSTRAINT ' + quotename(o.name) FROM sysobjects o JOIN sysobjects p ON o.parent_obj = p.id WHERE o.xtype = 'PK' Copy result and execute it. Note that if there are referencing foreign keys, it will not be possible to drop the PK. -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
|
Pages: 1 Prev: SQL 2005EE - 64 memory question Next: How to keep format when importing Excel into SQL. |