SQL笔记15:数据插入

插入数据

插入完整的行

例1

INSERT INTO customers
VALUES(1000000006,
		'Toy Land',
        '123 Any Street',
        'New York',
        'NY',
        '11111',
        'USA',
        NULL,
        NULL);

例2

INSERT INTO customers(cust_id,
					  cust_name,
					  cust_address,
                      cust_city,
                      cust_state,
                      cust_zip,
                      cust_country,
                      cust_contact,
                      cust_email)
VALUES(1000000007,
		'Toy Land',
        '123 Any Street',
        'New York',
        'NY',
        '11111',
        'USA',
        NULL,
        NULL);

插入部分行

例3

INSERT INTO customers(cust_id,
					  cust_name,
					  cust_address,
                      cust_city,
                      cust_state,
                      cust_zip,
                      cust_country)
VALUES(1000000008,
		'Toy Land',
        '123 Any Street',
        'New York',
        'NY',
        '11111',
        'USA');

插入检索出的数据

例4

INSERT INTO customers(cust_id,
					  cust_contact,
                      cust_email,
                      cust_address,
                      cust_city,
                      cust_sate,
                      cust_zip,
                      cust_country)
SELECT cust_id,
	   cust_contact,
       cust_email,
       cust_address,
	   cust_city,
       cust_sate,
       cust_zip,
	   cust_country
FROM custNew;

复制表

例5

CREATE TABLE custcopy AS SELECT * FROM customers;

挑战题

1.

Using INSERT and columns specified, add yourself to the Customers table.

INSERT INTO customers(cust_id,
					  cust_name,
					  cust_address,
                      cust_city,
                      cust_state,
                      cust_zip,
                      cust_country)
VALUES(1000000009,
		'Jianguo Peng',
        '123 Any Street',
        'New York',
        'NY',
        '11111',
        'CN');

2.

Make a backup copy of your Orders and OrderItems tables.

CREATE TABLE copy_orders AS SELECT * FROM orders;
CREATE TABLE copy_orderitems AS SELECT * FROM orderitems;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值