Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

mishra.anurag643_153409 avatar image
mishra.anurag643_153409 asked ·

What is the syntax for compound primary keys?

below create table throws an error :

I know clustering keys ae written after partition key , but why does below table throw an error if clustering keys are mentioned inside brackets ().

also can't we write primary key like :

primary key((partition key1,partiton key2),(clustering key1,clustering key2))

1608184726044.png

data modeling
1608184726044.png (21.3 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

The brackets only apply to composite partition keys. It doesn't apply to clustering keys.

In your case, the correct syntax is:

    PRIMARY KEY (id, name, age)

where id is the partition key, name and age are both clustering keys. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.