replace.md 712 字节
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
# Replace

假设有数据表如下

```sql
create table cust(
    id integer primary key ,
    first_name varchar(256),
    last_name varchar(256),
    city varchar(256)
);
```

下列replace语句中,有错误的是:

## 答案

```sql
replace into cust(id) set first_name = 'Mars', last_name = 'Liu' where id = 6; 
```

## 选项

### 标准的 replace

```sql
REPLACE INTO cust(id, first_name, last_name, city) values(1,'Mars', 'Liu', 'Tian Jin');
```

### 合法的插入操作

```sql
REPLACE INTO cust(first_name, last_name, city) values('Mars', 'Liu', 'Tian Jin');
```

### 合法的插入操作

```sql
REPLACE INTO cust(first_name, last_name, city)
SELECT first_name, last_name, city FROM book;
```