第15 16课 数据的插入更新和删除

154 阅读1分钟

插入

插入完整的行

insert into customers values
(
	'10000006',
    'Toy Land',
    '123 Any Street',
    'New York',
    'NY',
    '1111',
    'USA',
    null,
    null
);

更规范的写法:

insert into customers 
(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country,
cust_contact,
cust_email
)
values
(
	'10000007',
    'Toy Land',
    '123 Any Street',
    'New York',
    'NY',
    '1111',
    'USA',
    null,
    null
);

插入部分数据

insert into customers 
(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country
)
values
(
	'10000008',
    'Toy Land',
    '123 Any Street',
    'New York',
    'NY',
    '1111',
    'USA'
);

插入检索出的数据

insert into customers 
(
cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country
)
select

cust_id,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country

from custnew;

从一个表复制到另一个表

create table custcopy as 
select * 
from customers;

更新数据

update语句有三部分组成:

  • 更新的表
  • 列名和值
  • 确定更新行的过滤条件
update customers
set cust_email = null
where cust_id = '111111110';

删除数据