binary.md 1.8 KB
Newer Older
M
text  
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 89 90 91 92 93 94
# 二进制字符串

现在 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),
    description varchar(2000),
    ts timestamp default now()
);
```

他需要添加一个字段,用来保存订单的相关图片,由于特殊的业务需要,这些图片必须保存在数据库中,图片的大小不超过100K。那么他应该将建表语句修改为:

## 答案

```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),
    description varchar(2000),
    picture blob,
    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),
    description varchar(2000),
    picture varchar(100000),
    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),
    total_price decimal(12, 4),
    description varchar(2000),
    picture text,
    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),
    total_price decimal(12, 4),
    description varchar(2000),
    picture binary(100000),
    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),
    total_price decimal(12, 4),
    description varchar(2000),
    picture varbinary(100000),
    ts timestamp default now()
);
```