- 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.
- 平面設(shè)計初步
- 機(jī)器人創(chuàng)新實訓(xùn)教程
- Supervised Machine Learning with Python
- Photoshop CS3圖像處理融會貫通
- Pig Design Patterns
- 計算機(jī)網(wǎng)絡(luò)安全
- 單片機(jī)技術(shù)一學(xué)就會
- Dreamweaver CS6精彩網(wǎng)頁制作與網(wǎng)站建設(shè)
- Windows Server 2008 R2活動目錄內(nèi)幕
- Building a BeagleBone Black Super Cluster
- 會聲會影X4中文版從入門到精通
- Cortex-M3嵌入式處理器原理與應(yīng)用
- Machine Learning with Spark(Second Edition)
- ARM嵌入式開發(fā)實例
- 細(xì)節(jié)決定交互設(shè)計的成敗