diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.json" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.json" index 4234c280bb3c6bb75a85323185b11c8f651a6938..712a0aa6984d2d9138893d690b81c26db8437eb3 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/1.\346\225\260\345\200\274\347\261\273\345\236\213/numbers.json" @@ -1,6 +1,6 @@ { "type": "code_options", - "author": "Mars", + "author": "ccat", "source": "numbers.md", "notebook_enable": false, "exercise_id": "0093549d885b4eec8f556fc86cc60431" diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.json" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.json" index 068f60ed73bc02974ad85cb7b2a985121680d1bc..7de8c9002867c3ea186befaa884f434c6aabe965 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/2.\346\227\245\346\234\237\345\222\214\346\227\266\351\227\264\347\261\273\345\236\213/datetime.json" @@ -1,6 +1,6 @@ { "type": "code_options", - "author": "Mars", + "author": "ccat", "source": "datetime.md", "notebook_enable": false, "exercise_id": "9f51c5816b1047368bdab70cb20d5116" diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.json" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.json" index 80b0216a4914f68863f575774b51a16f729dd0c1..0f349f15a038583f8b1be50c42c5168d85cb730e 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/3.\346\226\207\346\234\254\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/description.json" @@ -1,6 +1,6 @@ { "type": "code_options", - "author": "Mars", + "author": "ccat", "source": "description.md", "notebook_enable": false, "exercise_id": "772f9b0947074197bbeb414fd5a094b0" diff --git "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.json" "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.json" index ac622bb210040a36347c1e4692e417accc975ce6..3c7a1acfa147e872c8889422d6c4152d8a344075 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/4.\346\225\260\346\215\256\347\261\273\345\236\213/4.\344\272\214\350\277\233\345\210\266\345\255\227\347\254\246\344\270\262\347\261\273\345\236\213/binary.json" @@ -1,6 +1,6 @@ { "type": "code_options", - "author": "Mars", + "author": "ccat", "source": "binary.md", "notebook_enable": false, "exercise_id": "b3cdc6ba96d544969c08fe697df32dde" diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" index 4db0936e8cd4831508df151799c6932925554202..6093a20ea034dc8072ecb58b504797c362d5630d 100644 --- "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/config.json" @@ -2,7 +2,9 @@ "node_id": "mysql-fcca525ab0f04f16834ded9b2b3f38a4", "keywords": [], "children": [], - "export": [], + "export": [ + "insert.json" + ], "keywords_must": [], "keywords_forbid": [], "group": 0 diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.json" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.json" new file mode 100644 index 0000000000000000000000000000000000000000..d91a7021935c59e8d86d97c6a6e45fc794575e8e --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "ccat", + "source": "insert.md", + "notebook_enable": false, + "exercise_id": "81e312020bb04761800918d54a7a5851" +} \ No newline at end of file diff --git "a/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" new file mode 100644 index 0000000000000000000000000000000000000000..636c7433e9bbd66a275e956438418ac07dd4e4cc --- /dev/null +++ "b/data/1.MySQL\345\210\235\351\230\266/5.\346\225\260\346\215\256\344\277\256\346\224\271/1.\346\217\222\345\205\245/insert.md" @@ -0,0 +1,54 @@ +# 插入 + +Goods 数据库中有一个表: + +```mysql +create table book( + id int primary key auto_increment, + title varchar(200) not null , + description varchar(1000) default '', + price decimal(12, 4), + isbn char(16) not null , + publish_at date not null +); +create unique index idx_book_isbn on book(isbn); +``` + +那么下列哪个选项的代码可以执行成功? + +## 答案 + +```mysql +insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, price, isbn, publish_at) select 'a other book title', 25.4, 'yy-yyyy-xxxx', '2019-12-1'; +``` + +## 选项 + +### 唯一键冲突 + +```mysql +insert into book(title, price, isbn, publish_at) select 'a book title', 25.4, 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, price, isbn, publish_at) select 'a other book title', 35.4, 'xx-xxxx-xxxx', '2019-12-1'; +``` + +### 缺少必要的列 + +```mysql +insert into book(price, isbn, publish_at) select 25.4, 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(price, isbn, publish_at) select 35.4, 'yy-yyyy-xxxx', '2019-12-1'; +``` + +### 类型错误 + +```mysql +insert into book(title, price, isbn, publish_at) select 'a book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, price, isbn, publish_at) select 'a other book title', 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; +``` + +### 违反非空约束 + +```mysql +insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; +insert into book(title, price, isbn, publish_at) select null, 'unknown', 'xx-xxxx-xxxx', '2019-12-1'; +``` diff --git a/data/tree.json b/data/tree.json index 6d738a07103e21f0e8b8ccf815bcd2bb65d5d0a4..9411c8b247c1eb9aa6e6d5d6fed6396f4e2de3cf 100644 --- a/data/tree.json +++ b/data/tree.json @@ -157,7 +157,13 @@ { "文本字符串类型": { "node_id": "mysql-27ff66e31d3d4118977cbbc04da6887e", - "keywords": [], + "keywords": [ + "text", + "varchar", + "char", + "字符串", + "文本" + ], "children": [], "keywords_must": [], "keywords_forbid": [] @@ -166,7 +172,11 @@ { "二进制字符串类型": { "node_id": "mysql-ec8f22f2c63a4f27bd12815644d0f3db", - "keywords": [], + "keywords": [ + "binary", + "blob", + "二进制" + ], "children": [], "keywords_must": [], "keywords_forbid": []