1-bob. Ma`lumotlar bazasining asosiy tushunchalari


CREATE VIEW Dateorders (odate, ocount) AS SELECT odate, COUNT (*)


Download 1.69 Mb.
bet44/80
Sana17.06.2023
Hajmi1.69 Mb.
#1542331
1   ...   40   41   42   43   44   45   46   47   ...   80
Bog'liq
ec613b75a51decaf6d60405d564c5683 MySQL po max

CREATE VIEW Dateorders (odate, ocount) AS SELECT odate, COUNT (*)


FROM Orders GROUP BY odate;
Bu faqat o‘qish uchun tasvir chunki agrеgat funksiya va GROUP BY mavjud.

CREATE VIEW Londoncust AS SELECT *


FROM Customers WHERE city = 'London';
Bu tasvir modifikatsiya qilinuvchi.

CREATE VIEW Sales (name, number, percentage) AS SELECT sname, snum, comm*100


FROM Salespeople WHERE city = 'SanJose';
Bu faqat o‘qish uchun, chunki "comm * 100" ifoda ishlatiladi.

CREATE VIEW Salesonthird AS SELECT *


FROM Salespeople

WHERE snum IN (SELECT snum FROM Orders


WHERE odate = 10/03/1990);
Bu ANSI bo‘yicha faqat o‘qish uchun so‘rov chunki ostki so‘rov mavjud. Lеkin ba‘zi dasturlarda modifikatsiya qilinuvchi bo‘lishi mumkin.

CREATE VIEW Someorders AS SELECT snum, onum, cnum FROM Orders


WHERE odate IN (10/03/1990,10/05/1990);
Bu modifikatsiya qilinuvchi tasvir.


Tasvirlarni o‘chirish. Tasvirlarni o‘chirish quyidagicha amalga oshiriladi:

DROP VIEW view_name;


Misol. CUSTOMERS jadvali asosida yaratilgan CUSTOMERS_VIEW tasvirni o‘chirish.

DROP VIEW CUSTOMERS_VIEW;


Tasvirni o‘zgartirish komandasi ALTER VIEW.

ALTER VIEW tasvir_nomi [(ustun_1, ustun_2, )] AS ifoda_SELECT


Masalan OrdersProductsCustomers tasvirni o‘zgartirish:


ALTER VIEW OrdersProductsCustomers


AS SELECT Orders.CreatedAt AS OrderDate, Customers.FirstName AS Customer, Products.ProductName AS Product, Products.Manufacturer AS Manufacturer FROM Orders

INNER JOIN Products ON Orders.ProductId = Products.Id INNER JOIN Customers ON Orders.CustomerId = Customers.Id;





Download 1.69 Mb.

Do'stlaringiz bilan baham:
1   ...   40   41   42   43   44   45   46   47   ...   80




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling