troubleshooting Question

alter table add second primary key

Avatar of Dany Balian
Dany BalianFlag for Lebanon asked on
DatabasesSybase DatabaseSQL
3 Comments1 Solution5529 ViewsLast Modified:
Dear experts,
i have 2 sybase databases.
1 used for production and 1 use for development.
all my tables have an autonumber primary key.

recently, i've taken a project of upgrading the software so that we have centralized management for many branches. and i need to add a second primary key called branchid on some of the tables.

normally when i do this in the gui i follow these steps.
1. add the new column branchid to the table (ofcourse it has to be not null because the table already has data)
2. update tablename set branchid=0 (or any value that i want)
3. modify the table so that it doesnt allow null values
4. set it as primary key (keeping the primary autonumbered pkey as well)

doing this programmatically:
1. i'm adding the column using alter table add column branchid null << successful
2. update table set branchid=0 << success
3. alter table tablename modify column branchid not null << success
4. alter table tablename add primary key (branchid) << i get an error saying that table already has a primary key

what is the syntax of altering a table from 1 pkey structure to a composite pkey structure??

i appreciate your help,


p.s. i dont wanna look cheap, but this question is urgent and 95 points are all i have left on my account.
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros