0

I have encountered a problem in sybase.

By searching in stackoverflow, I found this link.

But I found that incorrect in sybase, which gave me a syntax error warning. Are there any other ways that can change the primary key in sybase?

Community
  • 1
  • 1
Rob Ye
  • 63
  • 1
  • 7

2 Answers2

0

We can use sp_dropkey to drop the key and sp_primarykey to add the primary key.

sp_dropkey primary, MyTable

sp_primarykey MyTable, col1, col2,..,col8

Sumit Kumar
  • 160
  • 1
  • 5
  • Saying no primary key exist, while I create a table as specify the primary key – Rob Ye Jun 10 '16 at 12:17
  • can you show table and column and create table query you used ? – Sumit Kumar Jun 10 '16 at 12:24
  • ````create table S87EntityFolderMap ( cty_cde CountryCode not null , entity Entity not null , folder Folder not null , PRIMARY KEY CLUSTERED ( cty_cde, entity,folder ) on 'default' )```` – Rob Ye Jun 10 '16 at 13:13
  • for example, i want to add new column to this table and make it as one of primary key as well. – Rob Ye Jun 10 '16 at 13:14
0

1- Use :

sp_helpconstraint S87EntityFolderMap 

To get your Primary Key system Generated name

2- Then use alter table to drop it :

alter table S87EntityFolderMap drop constraint name_from_first_step
F Karam
  • 56
  • 7