COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
/* Theâm maåu tin vôùi moät soá coät */
INSERT INTO
TBLCUSTOMERS
(CustName,Username,Password,
Address,Tel,FaxNo,Email,Contact,
CountryCode,ProvinceCode)
Values ('Khach San CENTURY', ‘century’,
’1111’,’5
Le
Loi’,’8676767’,’8767676’,
‘[email protected]’,’Hoang
Anh’,
‘VNA’,’HCM’)
/* Theâm maåu tin vôùi moät soá coät */
INSERT INTO
TBLORDERS(OrderID,OrderDate,
CustID,Description,Amount)
Values ('11',curdate(),’1',
'Dat hang qua mang', 20000)
5.7.2. Insert vaøo baûng laáy giaù trò töø baûng khaùc:
INSERT INTO <Tablename1>[<columnname list>]
Select [columnname list]
From <Tablename2>
Where <Conditions>
Ví duï 8-17: INSERT vaøo baûng töø giaù trò cuûa baûng khaùc
/* Theâm maåu tin vôùi caùc coät cuï theå */
/* Chuyeån taát caû nhöõng hôïp ñoàng chi tieát töø baûng
tblOrderDetails vaøo baûng tblOrderDetailsHist */
INSERT INTO
TBLORDERDETAILSHIST(
ItemID,
OrderID,
No,
Qtty,
Price,
Discount,
Amount)
SELECT
ItemID,
OrderID,
No,
Qtty,
Price,
Discount,
Amount
From tblOrderDetails
ORDER BY OrderID ASC
/* Coù theå vieát laïi theâm maåu tin vôùi taát caû caùc coät nhö sau
Chuyeån taát caû nhöõng hôïp ñoàng chi tieát töø baûng tblOrderDetails vaøo baûng tblOrderDetailsHist vôùi ñieàu
kieän soá coät töông öùng trong baûng tblOrderDetails baèng vôùi soá coät trong baûng tblOrderDetailsHist, baïn coù
theå vieát laïi nhö sau */
Giaùo vieân: Phaïm Höõu Khang