description.md 1.8 KB
Newer Older
M
text  
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10
# 文本字段

Joe 在设计订单表,他已经完成了下列内容:

```mysql
create table orders (
    id int primary key auto_increment,
    item_id int,
    amount int,
    unit_price decimal(12, 4),
M
Mars Liu 已提交
11
    price decimal(12, 4),
M
text  
Mars Liu 已提交
12 13 14 15 16 17
    ts timestamp default now()
);
```

现在他需要给订单表加入一个 description 字段,这个字段需要保存订单的文字说明,这些文本不会超过两千字节, Joe 应该把建表语句修改为:

M
Mars Liu 已提交
18 19
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)

M
text  
Mars Liu 已提交
20 21 22 23 24 25 26 27
## 答案

```mysql
create table orders (
    id int primary key auto_increment,
    item_id int,
    amount int,
    unit_price decimal(12, 4),
M
Mars Liu 已提交
28
    price decimal(12, 4),
M
text  
Mars Liu 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    description varchar(2000),
    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),
M
Mars Liu 已提交
44
    price decimal(12, 4),
M
text  
Mars Liu 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57
    description char(2000),
    ts timestamp default now()
);
```

### B

```mysql
create table orders (
    id int primary key auto_increment,
    item_id int,
    amount int,
    unit_price decimal(12, 4),
M
Mars Liu 已提交
58
    price decimal(12, 4),
M
text  
Mars Liu 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71
    description varchar(256) default '',
    ts timestamp default now()
);
```

### C

```mysql
create table orders (
    id int primary key auto_increment,
    item_id int,
    amount int,
    unit_price decimal(12, 4),
M
Mars Liu 已提交
72
    price decimal(12, 4),
M
text  
Mars Liu 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85
    description text(2000),
    ts timestamp default now()
);
```

### D

```mysql
create table orders (
    id int primary key auto_increment,
    item_id int,
    amount int,
    unit_price decimal(12, 4),
M
Mars Liu 已提交
86
    price decimal(12, 4),
M
text  
Mars Liu 已提交
87 88 89 90
    description tinytext(2000),
    ts timestamp default now()
);
```