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/config.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/config.json" index e3097dce2a72bf8e4da768ca27014664b6582598..aaaab29a1744aeba596872568279d373720ba8cb 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/config.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/config.json" @@ -3,7 +3,7 @@ "keywords": [], "children": [], "export": [ - "number.json" + "numbers.json" ], "keywords_must": [], "keywords_forbid": [], 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/number.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/number.json" deleted file mode 100644 index a9e2d19b4e857af527b25b0b3b556e6371774fc3..0000000000000000000000000000000000000000 --- "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/number.json" +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "code_options", - "author": "ccat", - "source": "number.md", - "notebook_enable": false, - "exercise_id": "39244600680e40848e6ab8af71f22cf1" -} \ No newline at end of file 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" new file mode 100644 index 0000000000000000000000000000000000000000..4234c280bb3c6bb75a85323185b11c8f651a6938 --- /dev/null +++ "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" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Mars", + "source": "numbers.md", + "notebook_enable": false, + "exercise_id": "0093549d885b4eec8f556fc86cc60431" +} \ No newline at end of file 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/config.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/config.json" index 93b423ee0e18decee539c0ecf687d1217d22b433..bb8b705dfbd6a842d4d4fd9d0f996c19c64f959a 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/config.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/config.json" @@ -2,7 +2,9 @@ "node_id": "mysql-7256fe88bcf241d486c9e2e254ef66d9", "keywords": [], "children": [], - "export": [], + "export": [ + "datetime.json" + ], "keywords_must": [], "keywords_forbid": [], "group": 0 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" new file mode 100644 index 0000000000000000000000000000000000000000..068f60ed73bc02974ad85cb7b2a985121680d1bc --- /dev/null +++ "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" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Mars", + "source": "datetime.md", + "notebook_enable": false, + "exercise_id": "9f51c5816b1047368bdab70cb20d5116" +} \ No newline at end of file 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.md" "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.md" new file mode 100644 index 0000000000000000000000000000000000000000..a9d9aeb70624d8b2ceda8a304d0c285e5937edcd --- /dev/null +++ "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.md" @@ -0,0 +1,82 @@ +# 时间默认值 + +Joe 写了一个订单表的创建语句: + +```mysql +create table orders ( + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total_price decimal(12, 4) +); +``` + +现在,Joe 需要给这个表加入下单时间,即订单写入数据库的时间,那么他应该将这个语句修改为: + +## 答案 + +```mysql +create table orders ( + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total_price decimal(12, 4), + ts timestamp default now() +); +``` + +## 选项 + +### A + +```mysql +create table orders ( + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total_price decimal(12, 4), + ts varchar(16) default now() +); +``` + +### B + +```mysql +create table orders ( + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total_price decimal(12, 4), + ts varchar(16) format 'yyyy-mm-dd' +); +``` + +### C + +```mysql +create table orders ( + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total_price decimal(12, 4), + ts date default now() +); +``` + +### D + +```mysql +create table orders ( + id int primary key auto_increment, + item_id int, + amount int, + unit_price decimal(12, 4), + total_price decimal(12, 4), + ts datetime default now() +); +```