description.md 1.5 KB
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
# 文本字段

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

```postgresql
create table orders (
    id serial primary key,
    item_id int,
    amount int,
    unit_price money,
    price money,
    ts timestamp default now()
);
```

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

## 答案

```postgresql
create table orders (
    id serial primary key,
    item_id int,
    amount int,
    unit_price money,
    price money,
    description text,
    ts timestamp default now()
);
```

## 选项

### A

```postgresql
create table orders (
    id serial primary key,
    item_id int,
    amount int,
    unit_price money,
    price money,
    description char(2000),
    ts timestamp default now()
);
```

### B

```postgresql
create table orders (
    id serial primary key,
    item_id int,
    amount int,
    unit_price money,
    price money,
    description varchar(256) default '',
    ts timestamp default now()
);
```

### C

```postgresql
create table orders (
    id serial primary key,
    item_id int,
    amount int,
    unit_price money,
    price money,
    description text(2000),
    ts timestamp default now()
);
```

### D

```postgresql
create table orders (
    id serial primary key,
    item_id int,
    amount int,
    unit_price money,
    price money,
    description tinytext(2000),
    ts timestamp default now()
);
```