- DocumentDB SQL 教程
- DocumentDB SQL - 首頁
- DocumentDB SQL - 概述
- DocumentDB SQL - 選擇子句
- DocumentDB SQL - FROM 子句
- DocumentDB SQL - WHERE 子句
- DocumentDB SQL - 運算子
- DocumentDB - BETWEEN 關鍵字
- DocumentDB SQL - IN 關鍵字
- DocumentDB SQL - VALUE 關鍵字
- DocumentDB SQL - ORDER BY 子句
- DocumentDB SQL - 迭代
- DocumentDB SQL - 連線
- DocumentDB SQL - 別名
- DocumentDB SQL - 陣列建立
- DocumentDB - 標量表達式
- DocumentDB SQL - 引數化
- DocumentDB SQL - 內建函式
- LINQ to SQL 轉換
- JavaScript 整合
- 使用者自定義函式
- 複合 SQL 查詢
- DocumentDB SQL 有用資源
- DocumentDB SQL - 快速指南
- DocumentDB SQL - 有用資源
- DocumentDB SQL - 討論
DocumentDB SQL - 選擇子句
Azure 門戶提供了一個查詢資源管理器,允許我們對 DocumentDB 資料庫執行任何 SQL 查詢。我們將使用查詢資源管理器來演示查詢語言的許多不同功能和特性,從最簡單的查詢開始。
步驟 1 - 開啟 Azure 門戶,在資料庫邊欄選項卡中,點選查詢資源管理器邊欄選項卡。
請記住,查詢在集合的範圍內執行,因此查詢資源管理器允許我們在這個下拉列表中選擇集合。我們將保持它設定為我們的 Families 集合,其中包含三個文件。讓我們在這個例子中考慮這三個文件。
以下是 AndersenFamily 文件。
{
"id": "AndersenFamily",
"lastName": "Andersen",
"parents": [
{ "firstName": "Thomas", "relationship": "father" },
{ "firstName": "Mary Kay", "relationship": "mother" }
],
"children": [
{
"firstName": "Henriette Thaulow",
"gender": "female",
"grade": 5,
"pets": [ { "givenName": "Fluffy", "type": "Rabbit" } ]
}
],
"location": { "state": "WA", "county": "King", "city": "Seattle" },
"isRegistered": true
}
以下是 SmithFamily 文件。
{
"id": "SmithFamily",
"parents": [
{ "familyName": "Smith", "givenName": "James" },
{ "familyName": "Curtis", "givenName": "Helen" }
],
"children": [
{
"givenName": "Michelle",
"gender": "female",
"grade": 1
},
{
"givenName": "John",
"gender": "male",
"grade": 7,
"pets": [
{ "givenName": "Tweetie", "type": "Bird" }
]
}
],
"location": {
"state": "NY",
"county": "Queens",
"city": "Forest Hills"
},
"isRegistered": true
}
以下是 WakefieldFamily 文件。
{
"id": "WakefieldFamily",
"parents": [
{ "familyName": "Wakefield", "givenName": "Robin" },
{ "familyName": "Miller", "givenName": "Ben" }
],
"children": [
{
"familyName": "Merriam",
"givenName": "Jesse",
"gender": "female",
"grade": 6,
"pets": [
{ "givenName": "Charlie Brown", "type": "Dog" },
{ "givenName": "Tiger", "type": "Cat" },
{ "givenName": "Princess", "type": "Cat" }
]
},
{
"familyName": "Miller",
"givenName": "Lisa",
"gender": "female",
"grade": 3,
"pets": [
{ "givenName": "Jake", "type": "Snake" }
]
}
],
"location": { "state": "NY", "county": "Manhattan", "city": "NY" },
"isRegistered": false
}
查詢資源管理器以這個簡單的查詢 `SELECT * FROM c` 開啟,它簡單地檢索集合中的所有文件。雖然它很簡單,但它仍然與關係資料庫中的等效查詢非常不同。
步驟 2 - 在關係資料庫中,`SELECT *` 表示返回所有列,而在 DocumentDB 中,這意味著您希望結果中的每個文件都按照其在資料庫中的儲存方式返回。
但是,當您選擇特定的屬性和表示式而不是簡單地發出 `SELECT *` 時,您就會投影一個新的形狀,您希望結果中的每個文件都具有該形狀。
步驟 3 - 點選“執行”以執行查詢並開啟結果邊欄選項卡。
可以看到,WakefieldFamily、SmithFamily 和 AndersonFamily 都被檢索到了。
以下是作為 `SELECT * FROM c` 查詢的結果而檢索到的三個文件。
[
{
"id": "WakefieldFamily",
"parents": [
{
"familyName": "Wakefield",
"givenName": "Robin"
},
{
"familyName": "Miller",
"givenName": "Ben"
}
],
"children": [
{
"familyName": "Merriam",
"givenName": "Jesse",
"gender": "female",
"grade": 6,
"pets": [
{
"givenName": "Charlie Brown",
"type": "Dog"
},
{
"givenName": "Tiger",
"type": "Cat"
},
{
"givenName": "Princess",
"type": "Cat"
}
]
},
{
"familyName": "Miller",
"givenName": "Lisa",
"gender": "female",
"grade": 3,
"pets": [
{
"givenName": "Jake",
"type": "Snake"
}
]
}
],
"location": {
"state": "NY",
"county": "Manhattan",
"city": "NY"
},
"isRegistered": false,
"_rid": "Ic8LAJFujgECAAAAAAAAAA==",
"_ts": 1450541623,
"_self": "dbs/Ic8LAA==/colls/Ic8LAJFujgE=/docs/Ic8LAJFujgECAAAAAAAAAA==/",
"_etag": "\"00000500-0000-0000-0000-567582370000\"",
"_attachments": "attachments/"
},
{
"id": "SmithFamily",
"parents": [
{
"familyName": "Smith",
"givenName": "James"
},
{
"familyName": "Curtis",
"givenName": "Helen"
}
],
"children": [
{
"givenName": "Michelle",
"gender": "female",
"grade": 1
},
{
"givenName": "John",
"gender": "male",
"grade": 7,
"pets": [
{
"givenName": "Tweetie",
"type": "Bird"
}
]
}
],
"location": {
"state": "NY",
"county": "Queens",
"city": "Forest Hills"
},
"isRegistered": true,
"_rid": "Ic8LAJFujgEDAAAAAAAAAA==",
"_ts": 1450541623,
"_self": "dbs/Ic8LAA==/colls/Ic8LAJFujgE=/docs/Ic8LAJFujgEDAAAAAAAAAA==/",
"_etag": "\"00000600-0000-0000-0000-567582370000\"",
"_attachments": "attachments/"
},
{
"id": "AndersenFamily",
"lastName": "Andersen",
"parents": [
{
"firstName": "Thomas",
"relationship": "father"
},
{
"firstName": "Mary Kay",
"relationship": "mother"
}
],
"children": [
{
"firstName": "Henriette Thaulow",
"gender": "female",
"grade": 5,
"pets": [
"givenName": "Fluffy",
"type": "Rabbit"
]
}
],
"location": {
"state": "WA",
"county": "King",
"city": "Seattle"
},
"isRegistered": true,
"_rid": "Ic8LAJFujgEEAAAAAAAAAA==",
"_ts": 1450541624,
"_self": "dbs/Ic8LAA==/colls/Ic8LAJFujgE=/docs/Ic8LAJFujgEEAAAAAAAAAA==/",
"_etag": "\"00000700-0000-0000-0000-567582380000\"",
"_attachments": "attachments/"
}
]
但是,這些結果還包括所有以下劃線字元為字首的系統生成的屬性。
廣告