Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
svicky9
Posting Yak Master
232 Posts |
Posted - 2005-11-27 : 05:43:23
|
| Hi How do i remove the primary key for this tablecreate table table2(col1 int,col2 int,primary key(col2))ThanksVic |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2005-11-27 : 06:36:16
|
You'd have to know the name of the primary key constraint. If you created the table without giving the primary key an explicit name, then SQL Server will have given it an arbitrary name. However, given that you can only have one primary key on a table, it's pretty simple to find that name from the INFORMATION_SCHEMA views:DECLARE @pkname sysnameSELECT @pkname = CONSTRAINT_NAMEFROM INFORMATION_SCHEMA.TABLE_CONSTRAINTSWHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'table2' AND CONSTRAINT_TYPE = 'PRIMARY KEY'IF @pkname IS NOT NULLBEGIN PRINT @pkname EXECUTE ( 'ALTER TABLE table2 DROP CONSTRAINT ' + @pkname )END ELSE BEGIN PRINT 'No primary key'END |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-27 : 23:31:20
|
| orUse Enterprise Manager and remove itMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|