Mysql之複製一張表的內容到新表中
阿新 • • 發佈:2021-01-31
一、
這樣建立的新表order_archived內容和orders相同,但是沒主鍵
USE sql_store;
CREATE TABLE order_archived AS
SELECT * FROM orders
# 後面可以加上WHERE等子句
二、
USE sql_invoicing; CREATE TABLE invoices_archive AS 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) WHERE i.payment_date IS NOT NULL