刪除資料與刪除資料表
除了會使用 CREATE、INSERT 或 UPDATE,了解如何 DELETE 以及 DROP 資料表也同樣重要。使用 DELETE 可以刪除資料表中的特定列;使用 DROP TABLE 則可以移除整個資料表及其定義。
這兩個運算子的語法如下:
從 Employee 資料表刪除 lineID = 1 的那一列:
DELETE FROM Employee
WHERE lineID = 1;
刪除整個 Employee 資料表:
DROP TABLE Employee
你的任務是刪除先前建立的 Person 資料表中的部分列,最後再刪除整個資料表。
本練習屬於課程
SQL Server 的階層式與遞迴查詢
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
INSERT INTO Person
VALUES (1,'Andrew','Anderson','Adress 1','City 1','1986-12-30');
INSERT INTO Person
VALUES (2,'Peter','Jackson','Adress 2','City 2','1986-12-30');
INSERT INTO Person
VALUES (5,'Michaela','James','Adress 3','City 3','1976-03-07');
-- Delete the record for the person with the ID of 1
___ FROM ___
WHERE ___ = ___;
-- Delete the record with the name Jackson
___ FROM ___
___ ___ = 'Jackson';
SELECT *
FROM Person;