- Learning Apache Cassandra(Second Edition)
- Sandeep Yarabarla
- 189字
- 2021-07-03 00:19:33
Creating a table with a compound primary key
The syntax for creating tables with compound primary keys is a bit different from the single-column primary key syntax we saw in the previous chapter. We create a user_status_updates table with a compound primary key, as follows:
CREATE TABLE "user_status_updates" (
"username" text,
"id" timeuuid,
"body" text,
PRIMARY KEY ("username", "id")
);
In particular, instead of appending a single-column definition with a PRIMARY KEY modifier, we make a separate PRIMARY KEY declaration at the end of the list of columns, which itself specifies the two columns that make up the compound primary key.
While this is the only way to declare a compound primary key, it's also a perfectly valid way to declare a single-column primary key. So, our users table from the previous chapter could have been declared like this:
CREATE TABLE "users" (
"username" text,
"email" text,
"encrypted_password" blob,
PRIMARY KEY ("username")
);
Here, we simply move the PRIMARY KEY declaration to the end of the column list. It's a little less concise, but it has the exact same effect as a single-column definition with a PRIMARY KEY modifier.
- 工業機器人技術及應用
- Hands-On Machine Learning on Google Cloud Platform
- WOW!Illustrator CS6完全自學寶典
- 影視后期制作(Avid Media Composer 5.0)
- Security Automation with Ansible 2
- Ceph:Designing and Implementing Scalable Storage Systems
- Cloudera Administration Handbook
- 統計學習理論與方法:R語言版
- Visual FoxPro數據庫基礎及應用
- 運動控制系統
- Windows Server 2003系統安全管理
- Microsoft System Center Confi guration Manager
- 手機游戲策劃設計
- Redash v5 Quick Start Guide
- Eclipse全程指南