開始使用免費開始

將資料插入 person 與 order history

接下來,你要把資料插入兩個新建立的資料表 PersonHistory。請輸入以下訂單:

  1. Andrew Anderson 購買 iPhone XS,價格 1000
  2. 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;
編輯並執行程式碼