Products
деб номланган
маҳсулотлар жадвалига маълумотларни киритайлик.
4
Қулайлик учун 4 та
устунни олайлик. Сатрлар сони 9та бўлганлиги сабабли INSERT INTO
буйруғи 9 марта такрорланади.
Populate Products table - Products жадвалини тўлдириш
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('BR01', 'BRS01', 'Карамель', 1.29);
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('BR02', 'BRS01', 'Салат', 0.89 );
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('BR03', 'BRS01', 'Лўя', 1.09);
4
http ://forta.com/books/0672336073/
24
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('BNBG01', 'DLL01', 'Қаймоқ', 0.70);
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('BNBG02', 'DLL01', 'Творог ', 0.80);
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('BNBG03', 'DLL01', 'Карамель', 1.25);
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('RGAN01', 'DLL01', 'Ун', 0.65);
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('RYL01', 'FNG01', 'Қаймоқ', 0.79);
INSERT INTO Products(prod_id, vend_id, prod_name, prod_price)
VALUES('RYL02', 'FNG01', 'Лўя', 1.19);
Бунга мос маҳсулотлар жадвалининг кўриниши қуйидагича бўлади:
1-жадвал
Худди шу сингари INSERT INTO буйруғидан фойдаланиб,
Orders
деб номланган буюртмалар жадвалига маълумотлар
киритамиз[10]. Бунда сатрлар сони 5та бўлганлиги сабабли
INSERT INTO буйруғи 5 марта такрорланади.
Populate Orders table - Orders жадвалини тўлдириш
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20005, '2012-05-01', '1000000001');
25
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20006, '2012-01-12', '1000000003');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20007, '2012-01-30', '1000000004');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20008, '2012-02-03', '1000000005');
INSERT INTO Orders(order_num, order_date, cust_id)
VALUES(20009, '2012-02-08', '1000000001');
Orders буюртмалар жадвалинингкўриниши қуйидагича бўлади :
2-жадвал
order_num
order_date
cust_id
20005
2012-05-01
1000000001
20006
2012-01-12
1000000003
20007
2012-01-30
1000000004
20008
2012-02-03
1000000005
20009
2012-02-08
1000000001
Қолган 3 та - Customers(Мижозлар),Vendors(Таъминловчилар) ва
OrderItems (Буюртма элементлари) жадвалларга ҳам маълумотлар
киритамиз.
5
Populate Customers table - Customers жадвалини тўлдириш
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state,
cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000001', 'Village Toys', '200 Maple Lane', 'Detroit', 'MI', '44444',
'USA', 'John Smith', 'sales@villagetoys.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state,
cust_zip, cust_country, cust_contact)
VALUES('1000000002', 'Kids Place', '333 South Lake Drive', 'Columbus', 'OH',
'43333', 'USA', 'Michelle Green');
5
http ://forta.com/books/0672336073/
26
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state,
cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000003', 'Fun4All', '1 Sunny Place', 'Muncie', 'IN', '42222', 'USA',
'Jim Jones', 'jjones@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state,
cust_zip, cust_country, cust_contact, cust_email)
VALUES('1000000004', 'Fun4All', '829 Riverside Drive', 'Phoenix', 'AZ', '88888',
'USA', 'Denise L. Stephens', 'dstephens@fun4all.com');
INSERT INTO Customers(cust_id, cust_name, cust_address, cust_city, cust_state,
cust_zip, cust_country, cust_contact)
VALUES('1000000005', 'The Toy Store', '4545 53rd Street', 'Chicago', 'IL', '54545',
'USA', 'Kim Howard');
-- ----------------------
-- Populate Vendors table – Vendors жадвалини тўлдириш
-- ----------------------
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city,
vend_state, vend_zip, vend_country)
VALUES('BRS01','Bears R Us','123 Main Street','Bear Town','MI','44444', 'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city,
vend_state, vend_zip, vend_country)
VALUES('BRE02','Bear Emporium','500 Park Street','Anytown','OH','44333',
'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city,
vend_state, vend_zip, vend_country)
VALUES('DLL01','Doll House Inc.','555 High Street','Dollsville','CA','99999',
'USA');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city,
vend_state, vend_zip, vend_country)
VALUES('FRB01','Furball Inc.','1000 5th Avenue','New York','NY','11111',
'USA');
27
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city,
vend_state, vend_zip, vend_country)
VALUES('FNG01','Fun and Games','42 Galaxy Road','London', NULL,'N16 6PS',
'England');
INSERT INTO Vendors(vend_id, vend_name, vend_address, vend_city,
vend_state, vend_zip, vend_country)
VALUES('JTS01','Jouets et ours','1 Rue Amusement','Paris', NULL,'45678',
'France');
-- ----------------------
Populate OrderItems table - OrderItems жадвалини тўлдириш
-- -------------------------
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 1, 'BR01', 100, 5.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20005, 2, 'BR03', 100, 10.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 1, 'BR01', 20, 5.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 2, 'BR02', 10, 8.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20006, 3, 'BR03', 10, 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 1, 'BR03', 50, 11.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 2, 'BNBG01', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 3, 'BNBG02', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20007, 4, 'BNBG03', 100, 2.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
28
VALUES(20007, 5, 'RGAN01', 50, 4.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 1, 'RGAN01', 5, 4.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 2, 'BR03', 5, 11.99);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 3, 'BNBG01', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 4, 'BNBG02', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20008, 5, 'BNBG03', 10, 3.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 1, 'BNBG01', 250, 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 2, 'BNBG02', 250, 2.49);
INSERT INTO OrderItems(order_num, order_item, prod_id, quantity, item_price)
VALUES(20009, 3, 'BNBG03', 250, 2.49);
Customers(Мижозлар),Vendors(Таъминловчилар) ва OrderItems (Буюртма
элементлари) жадвалларининг кўриниши иловада келтирилган.
Юқорида келтирилган жадваллардан кейинги бобда сўров яратишда,
жумладан, сатрларни ва группаларни фильтрлаш, маълумотларни саралаш ва
гуруҳлаш жараѐнида фойдаланамиз.
Бундан ташқари, бу бобда биз сўров яратишда Laptop номли
портатив компьютерлар (ПК) жадвали,
Product номли
маҳсулот
жадвали ва
PC
номли жадваллардан фойдаланамиз. Бунда сўров
яратишнинг
айрим
масалалари,
жумладан,
My
SQL
да
ишлатиладиган INNER JOIN ва LEFT JOIN каби бирлаштириш
операторларидан, Transact-SQL да ишлатиладиган TRUNCATE
TABLE
буйруғидан фойдаланиб сўровлар яратиш назарда
тутилган.
29
II-боб. SQL тилининг қўлланилиши
2.1. SQL тилида сўров яратиш. SELECT инструкцияси
Бизга маълумки, SQL инструкциялари оддий инглиз атамаларидан
иборат.Бу атамалар
Do'stlaringiz bilan baham: |