description.md 1.6 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 18 19 20 21 22 23 24 25
    ts timestamp default now()
);
```

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

## 答案

```mysql
create table orders (
    id int primary key auto_increment,
    item_id int,
    amount int,
    unit_price decimal(12, 4),
M
Mars Liu 已提交
26
    price decimal(12, 4),
M
text  
Mars Liu 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    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 已提交
42
    price decimal(12, 4),
M
text  
Mars Liu 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55
    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 已提交
56
    price decimal(12, 4),
M
text  
Mars Liu 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69
    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 已提交
70
    price decimal(12, 4),
M
text  
Mars Liu 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83
    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 已提交
84
    price decimal(12, 4),
M
text  
Mars Liu 已提交
85 86 87 88
    description tinytext(2000),
    ts timestamp default now()
);
```