第三章
第一节. 列属性| Column Attributes[插入,更新和删除数据]
#
#
#
#
#
第二节. 插入单行| Inserting a Row
INSERT INTO customers
VALUES (DEFAULT, 'John', 'Smith', '1990-01-01', DEFAULT, 'ADDRESS', 'city', 'CA', DEFAULT)
第三节. 插入多行| Inserting Multiple Row
INSERT INTO shippers (name)
VALUES ('Shipper1'),
('Shipper2'),
('shipper3')
第三节.作业练习
INSERT INTO products (name, quantity_in_stock, unit_price)
VALUES ('product1', 5, 1.95),
('product2', 6, 1.95),
('product3', 7, 1.95)
第四节. 插入分层行| Inserting Hierachical Rows
INSERT INTO orders (customer_id, order_date, status)
VALUES (1, '2019-01-02', 1);
INSERT INTO order_items
VALUES
(LAST_INSERT_ID(), 1, 1, 2.95),
(LAST_INSERT_ID(), 2, 1, 3.95)
第五节. 创建表复制| Creating a copy of a table
CREATE TABLE orders_archived AS
SELECT * FROM orders
INSERT INTO orders_archived()
SELECT *
FROM orders
WHERE order_date < '2019-01-01'
第五节. 作业练习
USE sql_invoicing;
SELECT
i.invoice_id,
i.number,
c.name AS client,
i.invoice_total,
i.payment_total,
i.invoice_Date,
i.payment_date,
i.due_Date
FROM invoices i
JOIN clients c
USING (client_id)
第六节. 更新单行| Updating a Single Row
UPDATE invoices
SET payment_total = 10, payment_date = '2019-03-01'
WHERE invoice_id = 1
第七节. 更新多行| Updating Multiple Rows
UPDATE invoices
SET
payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE client_id IN (3,4)
第七节. 作业练习
USE sql_Store;
UPDATE customers
SET points = points +50
WHERE birth_date < '1990-01-01'
第八节. 在Updates中用子查询|Using Subqueries in Updates
USE sql_invoicing;
UPDATE invoices
SET
payment_total = invoice_total * 0.5,
payment_date = due_date
WHERE client_id =
(SELECT client_id
FROM clients
WHERER name = 'Myworks')
第九节. 删除行|Deleting Rows
DELETE FROM invoices
WHERE client_id = (
SELECT *
FROM clients
WHERE name = 'Myworks'
)
第十节. 恢复数据库|Restoring the Databases
## FILE ----> Open SQL Script----->找到自己的数据并导入