- 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.
- 計算機應用
- 中文版Photoshop CS5數碼照片處理完全自學一本通
- 商戰數據挖掘:你需要了解的數據科學與分析思維
- 模型制作
- SharePoint 2010開發最佳實踐
- Implementing Splunk 7(Third Edition)
- Learn CloudFormation
- Visual Basic.NET程序設計
- Windows Server 2008 R2活動目錄內幕
- 零起點學西門子S7-200 PLC
- LMMS:A Complete Guide to Dance Music Production Beginner's Guide
- SQL Server數據庫應用基礎(第2版)
- ZigBee無線通信技術應用開發
- 三菱FX/Q系列PLC工程實例詳解
- NetSuite ERP for Administrators