Amaliy mashg’ulotlarida berilgan topshiriqlar
Download 395.12 Kb.
|
SQL command 29-11-2021
- Bu sahifa navigatsiya:
- CustomerID CustomerName ContactName
- CustomerName ContactName
- Quyidagi SQLkodi "Product" jadvalidagi ortacha narxdan yuqori narxga ega har bir mahsulotni korinishni yaratadi
- ProductID ProductName SupplierID
- Avg_price 29.2 SQL kodi Natijasi
- ProductName Price
- 16 LABORATORIYA ISHI Mavzu: SQLda protsedura lar yaratish I s h d an m aq s ad
- Protsedura yaratish: DELIMITER // CREATE PROCEDURE protsedura_nomi(protsedura prototipi) BEGIN {protsedura so’rovlar amallar… maydoni}
- INSERT INTO person VALUES (John, 14);
Masalani qo`yilishi: Predmet soha ma`lumotlar bazasi shakllantirilgandan so`ng ob`yektlarda tasavvurlarni yaratish va VIEW dan foydalanish.
VIEW yaratish va o’chirishning so’rovi sintaksisi CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition; DROP VIEW view_name; Masalan: CREATE VIEW Braziliya_xaridorlari AS SELECT xaridor_familiyasi, xaridor_ismi FROM xaridorlar WHERE mamlakat = "Braziliya"; DROP VIEW Braziliya; CREATE VIEW [Brazil Customers] AS SELECT CustomerName, ContactName FROM Customers WHERE Country = 'Brazil'; Example.csv yoki Customer.csv , Products.csv Customer
So’rov Natijasi
Quyidagi SQLkodi "Product" jadvalidagi o'rtacha narxdan yuqori narxga ega har bir mahsulotni ko'rinishni yaratadi: CREATE VIEW [Products Above Average Price] AS SELECT ProductName, Price FROM Products WHERE Price > (SELECT AVG(Price) FROM Products); LOAD DATA LOCAL INFILE 'c:/tmp/Example.csv' INTO TABLE customers FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 ROWS; Products
SQL kodi Natijasi
16 LABORATORIYA ISHI Mavzu: SQLda protseduralar yaratish Ishdan maqsad: Berilgan predmet soha ma`lumotlar bazasi uchun protsedura yaratish. Masalani qo`yilishi: Predmet soha ma`lumotlar bazasi shakllantirilgandan so`ng ob`yektlarda proseduralarni yaratish va ulardan foydalanish. Protsedura yaratish: DELIMITER // CREATE PROCEDURE protsedura_nomi(protsedura prototipi) BEGIN {protsedura so’rovlar amallar… maydoni} END// protsedurani chaqirish: CALL protsedura_nomi(@prototip)// protsedura natijasini ko’rish: SELECT @prototip; DELIMITER // CREATE PROCEDURE Talaba BEGIN SELECT * FROM Talaba; END // DELIMITER ; ….. ….. CALL Talaba; create database qwerty123; use qwerty123; CREATE TABLE person (name varchar(45), age int); INSERT INTO person VALUES ('Matthew', 25), ('Mark', 20); CREATE TABLE average_age (average double); INSERT INTO average_age SELECT AVG(age) FROM person; CREATE TABLE person_archive ( name varchar(45), age int, time timestamp DEFAULT NOW()); delimiter // CREATE TRIGGER person_bi BEFORE INSERT ON person FOR EACH ROW IF NEW.age < 18 THEN SIGNAL SQLSTATE '50001' SET MESSAGE_TEXT = 'Person must be older than 18.'; END IF; // delimiter ; SELECT * FROM average_age; DELIMITER // CREATE TRIGGER person_ai AFTER INSERT ON person FOR EACH ROW UPDATE average_age SET average = (SELECT AVG(age) FROM person); // delimiter ; CREATE TABLE person_archive ( name varchar(45), age int, time timestamp DEFAULT NOW()); INSERT INTO person VALUES ('John', 14); Customer
Download 395.12 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling