diff --git "a/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/config.json" "b/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/config.json" index 0ef4a24fb63054c862887b8183eff6c28b78197f..c382fbaec98ff65e2075772595f35955536f455d 100644 --- "a/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/config.json" +++ "b/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/config.json" @@ -1,5 +1,7 @@ { "keywords": [], "node_id": "oceanbase-4d176da86e544f98acdb7b473d14902a", - "title": "INSERT" + "title": "INSERT", + "notebook_enable": false, + "export": ["insert.json"] } \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/insert.json" "b/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/insert.json" new file mode 100644 index 0000000000000000000000000000000000000000..e33023ffdb88d94cd595a6ae9426b3fd098fabe8 --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/insert.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "insert.md" +} \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/insert.md" "b/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/insert.md" new file mode 100644 index 0000000000000000000000000000000000000000..8b1a3463a3b85e4e479975895bf75146e3882156 --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/4.INSERT/insert.md" @@ -0,0 +1,30 @@ +# Insert + +下列哪一个选项的插入语句有错误? + +## 答案 + +```sql +insert into cust set first_name = 'Mars', last_name = 'Liu', city = 'Tian Jin'; +``` + +## 选项 + +### 标准插入语句 + +```sql +insert into cust(first_name, last_name, city) values('Mars', 'Liu', 'Tian Jin'); +``` + +### insert 可以使用 select 子句 + +```sql +insert into cust(first_name, last_name, city) select 'Mars', 'Liu', 'Tian Jin'; +``` + +### insert 可以插入多条 values + +```sql +insert into cust(first_name, last_name, city) + values ('Mars', 'Liu', 'Tian Jin'), ('Milly', 'Lee', 'Tian Jin'); +``` \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/config.json" "b/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/config.json" index 28504408bffeea10ea5bbc84b56c326e0bcb11b8..c346a7dd29c09a153a0e11047db46db0a139c027 100644 --- "a/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/config.json" +++ "b/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/config.json" @@ -1,5 +1,7 @@ { "keywords": [], "node_id": "oceanbase-331c385ebc2448198f48564851555c06", - "title": "UPDATE" + "title": "UPDATE", + "notebook_enable": false, + "export": ["update.json"] } \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/update.json" "b/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/update.json" new file mode 100644 index 0000000000000000000000000000000000000000..61174dd294814e366ddb5ead4a2b5f8f5eff11cf --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/update.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "update.md" +} \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/update.md" "b/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/update.md" new file mode 100644 index 0000000000000000000000000000000000000000..f71b45ceec37436c4c30d473eebd5d6cf2c926dc --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/5.UPDATE/update.md" @@ -0,0 +1,29 @@ +# Update + +下面选项中,有错的是: + +## 答案 + +```sql +update cust(first_name) values('mars'); +``` + +## 选项 + +### 生产环境下不带 where 的update 通常是极度危险的,但是合法 + +```sql +update cust set first_name = 'Mars'; +``` + +### 标准 sql + +```sql +update cust set first_name='Mars' where id = 1234; +``` + +### Update 多个字段也是常用操作 + +```sql +update cust set first_name='Mars', last_name='Liu' where id = 1234; +``` \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/config.json" "b/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/config.json" index 5dcccf8fbc43dd34c50df10fa803c7c0133e15d3..0ccc5018763a1b263b1a83ac19bf6affab9058b8 100644 --- "a/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/config.json" +++ "b/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/config.json" @@ -1,5 +1,6 @@ { "keywords": [], "node_id": "oceanbase-704cfa03b69449b4bed5dc753bf5b7e7", - "title": "DELETE" + "title": "DELETE", + "export": "delete.json" } \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/delete.json" "b/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/delete.json" new file mode 100644 index 0000000000000000000000000000000000000000..440c13c5c18312371637e68a73f98ba311b0d828 --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/delete.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "delete.md" +} \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/delete.md" "b/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/delete.md" new file mode 100644 index 0000000000000000000000000000000000000000..09540fc2fb8765edf41f4810cf0308ffecbdb3f5 --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/6.DELETE/delete.md" @@ -0,0 +1,30 @@ +# Delete + +下列删除语句中,有错误的是: + +## 答案 + +```sql +delete from cust(id, last_name, first_name, city) where id = 5; +``` + +## 选项 + +### 在生产环境不带 where 的 delete 是极度危险的操作,但是它仍然合法 + +```sql +delete from cust; +``` + +### 标准的删除操作 + +```sql +delete from cust where id=2341; +``` + +### 删除操作可以带有子查询 + +```sql +delete from cust where id in (select id from cust where city='Tian Jin'); +``` + diff --git "a/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/config.json" "b/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/config.json" index 03b8165d94c00060c8665167314de52f436f8a6e..d30c426043f38843b4516ff988442e49cfd50254 100644 --- "a/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/config.json" +++ "b/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/config.json" @@ -1,5 +1,6 @@ { "keywords": [], "node_id": "oceanbase-2884a0055c714346ba751c2f653e8445", - "title": "REPLACE" + "title": "REPLACE", + "export": ["replace.json"] } \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/replace.json" "b/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/replace.json" new file mode 100644 index 0000000000000000000000000000000000000000..533de3b774ed0f8ad75163b829edbf478adda3c4 --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/replace.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "replace.md" +} \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/replace.md" "b/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/replace.md" new file mode 100644 index 0000000000000000000000000000000000000000..2a76886d3df7a7b46b52dc28d2ad131daf54c6a1 --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/7.REPLACE/replace.md" @@ -0,0 +1,41 @@ +# Replace + +假设有数据表如下 + +```sql +create table cust( + id integer primary key , + first_name varchar(256), + last_name varchar(256), + city varchar(256) +); +``` + +下列replace语句中,有错误的是: + +## 答案 + +```sql +replace into cust(id) set first_name = 'Mars', last_name = 'Liu' where id = 6; +``` + +## 选项 + +### 标准的 replace + +```sql +REPLACE INTO cust(id, first_name, last_name, city) values(1,'Mars', 'Liu', 'Tian Jin'); +``` + +### 合法的插入操作 + +```sql +REPLACE INTO cust(first_name, last_name, city) values('Mars', 'Liu', 'Tian Jin'); +``` + +### 合法的插入操作 + +```sql +REPLACE INTO cust(first_name, last_name, city) +SELECT first_name, last_name, city FROM book; +``` \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/config.json" "b/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/config.json" index 46f2cc21e31785576da166c72c9b421b02984535..ec5121966d68f017374626a8e720ff092f37dc1f 100644 --- "a/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/config.json" +++ "b/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/config.json" @@ -1,5 +1,6 @@ { "keywords": [], "node_id": "oceanbase-8526e5c5374b4081b9a5c698b9748856", - "title": "提交事务" + "title": "提交事务", + "export": "transaction.json" } \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/transaction.json" "b/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/transaction.json" new file mode 100644 index 0000000000000000000000000000000000000000..7efcf48fc9dd6d6e4c44a15802bbb4f1f6ecd9fb --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/transaction.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "刘鑫", + "source": "transaction.md" +} \ No newline at end of file diff --git "a/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/transaction.md" "b/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/transaction.md" new file mode 100644 index 0000000000000000000000000000000000000000..e320d3ea95a8eadc9b6546ee9bf2e19d2b16ba0a --- /dev/null +++ "b/data/2.OceanBase\344\270\255\351\230\266/8.\346\217\220\344\272\244\344\272\213\345\212\241/transaction.md" @@ -0,0 +1,41 @@ +# Transaction + +下列选项中,哪个可以正确的保证 channel 表和 posts 表的同步修改? + +## 答案 + +```sql +begin; + insert into posts(title, content) select ?, ?; + update channel set posts = posts +1 where channel_id = ?; +commit; +``` + +## 选项 + +### 没有 commit + +```sql +begin; + insert into posts(title, content) select ?, ?; + update channel set posts = posts +1 where channel_id = ?; +end; +``` + +### 没有创建事务 + +```sql +insert into posts(title, content) select ?, ?; +update channel set posts = posts +1 where channel_id = ?; +commit; +``` + +### 多次提交 + +```sql +begin; + insert into posts(title, content) select ?, ?; +commit; + update channel set posts = posts +1 where channel_id = ?; +commit; +``` \ No newline at end of file