提交 079814a1 编写于 作者: M Mars Liu

datetime

上级 35740d4c
......@@ -3,7 +3,7 @@
"keywords": [],
"children": [],
"export": [
"number.json"
"numbers.json"
],
"keywords_must": [],
"keywords_forbid": [],
......
{
"type": "code_options",
"author": "ccat",
"source": "number.md",
"author": "Mars",
"source": "numbers.md",
"notebook_enable": false,
"exercise_id": "39244600680e40848e6ab8af71f22cf1"
"exercise_id": "0093549d885b4eec8f556fc86cc60431"
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "mysql-7256fe88bcf241d486c9e2e254ef66d9",
"keywords": [],
"children": [],
"export": [],
"export": [
"datetime.json"
],
"keywords_must": [],
"keywords_forbid": [],
"group": 0
......
{
"type": "code_options",
"author": "Mars",
"source": "datetime.md",
"notebook_enable": false,
"exercise_id": "9f51c5816b1047368bdab70cb20d5116"
}
\ No newline at end of file
# 时间默认值
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()
);
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册