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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 delete primary key constraint without knowing tabl

Author  Topic 

eddie
Starting Member

45 Posts

Posted - 2001-05-03 : 14:54:40
I am trying to check to see if a primary key exists and then delete it if it does but I will not necessarily know the table it is on. Here is my scenario, I am updating some tables, the database could possibly have two versions of the same table, an old one and a new one. I want to put a pk on the new one. I am running into trouble because the pk of the same name is on the old table. I want to delete this pk regardless of the table so that I can use it on the new table.
I have the following code which seems to work but when I view the tables, they now both have primary keys of the same name..is this a problem?

if object_id('ex.pk_example') is not null
delete from sysobjects where name='pk_example'
go

whereas I used to have this:
if object_id('ex.pk_example') is not null
alter table ex.example
drop constraint pk_example
go

Thanks,
Eddie




Edited by - eddie on 05/03/2001 14:55:30
   

- Advertisement -