Composite key

Hello,
i have to addcomposite to an existing table .
The table already has primary key defined .

Any suggestions?

Thanks
RIASAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
So whats the question here, do you need the syntax ? check this link https://docs.microsoft.com/en-us/sql/t-sql/statements/create-index-transact-sql?view=sql-server-2017
0
Éric MoreauSenior .Net ConsultantCommented:
you want to replace your existing primary key with a new one?

drop your existing key:
ALTER TABLE myTable
DROP CONSTRAINT pk_myConstraint  

Open in new window


create your new key:
ALTER TABLE myTable
    ADD CONSTRAINT pk_myConstraint PRIMARY KEY (Column1,Column2)

Open in new window

0
RIASAuthor Commented:
Eric,
Get an error

XYZ is not a constraint.
Msg 3727, Level 16, State 0, Line 4
Could not drop constraint. See previous errors.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Éric MoreauSenior .Net ConsultantCommented:
can you do it using the designer in SSMS? if you can, just delete the PK from the UI.

otherwise, check your spelling.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RIASAuthor Commented:
Tried it but no luck
0
Éric MoreauSenior .Net ConsultantCommented:
why no luck? might not have enough privileges?
0
RIASAuthor Commented:
Sorry Eric, Yes it worked !
0
RIASAuthor Commented:
NNow this:
Msg 8111, Level 16, State 1, Line 3
Cannot define PRIMARY KEY constraint on nullable column in table 'TABLE1'.
Msg 1750, Level 16, State 0, Line 3
Could not create constraint or index. See previous errors.
0
Éric MoreauSenior .Net ConsultantCommented:
As the message says: one of your column is nullable. A primary key cannot be created on nullable columns.
0
RIASAuthor Commented:
Thanks Eric!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.