將資料插入 person 與 order history
接下來,你要把資料插入兩個新建立的資料表 Person 與 History。請輸入以下訂單:
- Andrew Anderson 購買 iPhone XS,價格 1000
- Sam Smith 購買 MacBook Pro,價格 1800
將顧客與其訂單插入資料表時,請確認:
- 主鍵(primary key)是唯一的
- 你使用了正確的外鍵(foreign key)
本練習屬於課程
SQL Server 的階層式與遞迴查詢
練習說明
- 為
ID=1的人 Andrew Anderson 插入新資料。 - 為第二個人
ID=2的 Sam Smith 插入新資料。 - 為 Andrew Anderson 新增一筆訂單:
iPhone XS,價格1000。 - 為 Sam Smith 新增一筆訂單:
MacBook Pro,價格1800。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Insert new data into the table Person
___ INTO ___
___ (1,___,'Anderson','Union Ave 10','New York','1986-12-30');
___ ___ Person
VALUES (___,___,___,'Flushing Ave 342','New York','1986-12-30');
-- Insert new data into the table History
___ ___ History
___ (1,'iPhone XS',___,___);
INSERT ___ ___
___ (___,'MacBook Pro',1800,___);
SELECT *
FROM History;