Microsoft Word 3-dedline (1)
Download 231.3 Kb. Pdf ko'rish
|
dedline3
1. Har bir talaba o’ziga berilgan predmet soha mavzusi bo’yicha INDEX, VIEWlar yaratishi va natijasi bilan ko’rsatib o’tishi kerak. mysql> CREATE INDEX index_name ON Xodimlar(ism); Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> ALTER TABLE xodimlar DROP INDEX index_name: Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> CREATE VIEW mijoz AS -> SELECT `ism`, `familiya` -> FROM `xodimlar` -> WHERE `ism`='Nurshodbek'? Query OK, 0 rows affected (0.01 sec) mysql> SELECT * FROM mijoz? +----------+-------------+ | ism | familiya | +----------+-------------+ | Nurshodbek | Shokirov | | Javohir | Turgunov | | Asror | Ahmedov | +----------+-------------+ 3 rows in set (0.00 sec) 2. Har bir talaba o’ziga berilgan predmet soha mavzusi bo’yicha FUNCTIONlar yaratishi va natijasi bilan ko’rsatib o’tishi’) kerak. mysql> delimiter ? mysql> create function fx(a varchar(100)) -> returns varchar(100) -> reads sql data -> begin -> declare c varchar(100); -> if a='Nurshodbek' then set c='Bu Nurshodbek'; -> elseif a!='Nurshodbek' then set c='Menga Nurshodbek kerak' ; -> end if; -> return c; -> end ? Query OK, 0 rows affected (0.03 sec) mysql> SELECT fx('Nurshodbek')? +----------------+ | fx('Nurshodbek') | +----------------+ | Bu Nurshodbek | +----------------+ 1 row in set (0.00 sec) mysql> SELECT fx('Javohir')? +---------------------------+ | fx('Javohir') | +---------------------------+ | 'Menga Nurshodbek kerak | +----------------------------+ 1 row in set (0.00 sec) 3. Har bir talaba o’ziga berilgan predmet soha mavzusi bo’yicha TRIGGERlar yaratishi va natijasi bilan ko’rsatib o’tishi kerak. 1. BEFORE INSERT mysql> CREATE TRIGGER salary_verify before insert ON `xodimlar` for each row -> begin -> if new.maosh<2000000 then set new.maosh=2000000; -> end if; -> end? Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO `xodimlar` VALUES(11, ' asdf ', 'sdfg', 2017, 1800000 , 'asdf', 8)? Query OK, 1 row affected (0.01 sec) mysql> SELECT ism, maosh from `xodimlar`? +-------------+---------+ | ism | maosh | +-------------+---------+ | Nurshodbek | 5000000 | | Javohir | 2500000 | | Xondamir | 2500000 | | Behruz | 2200000 | | Abduvohid | 2200000 | | Shahriyor | 2000000 | | Nodirbek | 2000000 | | MuhammadAli | 3000000 | | Asror | 3000000 | | asdf | 2000000 | +-------------+---------+ 10 rows in set (0.00 sec) 2. AFTER INSERT mysql> CREATE TRIGGER control after insert ON `sifat_nazorati` for each row -> begin -> if new.nazoratchi_xodim is null then -> INSERT INTO sifat_nazorati (nazoratchi_xodim) VALUES(' Kursatilmagan '); -> end if; -> end? Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO `sifat_nazorati` VALUES(3, 'asdf', 12, NULL)? Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM sifat_nazorati? +------------+------------------------+---------------+------------------+ | nazorat_id | sifat_tekshirish_usuli | xodimlar_soni | nazoratchi_xodim | +------------+------------------------+---------------+------------------+ | 3 | asdf | 12 | Kursatilmagan | +------------+------------------------+---------------+------------------+ 1 row in set (0.00 sec) 3. BEFORE UPDATE mysql> CREATE TRIGGER salary before update ON `xodimlar` for each row -> begin -> if new.maosh>5000000 then set new.maosh=5000000; -> end if; -> end? Query OK, 0 rows affected (0.01 sec) mysql> UPDATE `xodimlar` set maosh=6000000? Query OK, 9 rows affected (0.01 sec) Rows matched: 10 Changed: 9 Warnings: 0 mysql> select ism, maosh from xodimlar? +-------------+---------+ | ism | maosh | +-------------+---------+ | INurshodbek | 5000000 | | Javohir | 5000000 | | Xondamir | 5000000 | | Behruz | 5000000 | | Abduvohid | 5000000 | | Shahriyor | 5000000 | | Nodirbek | 5000000 | | MuhammadAli | 5000000 | | Asror | 5000000 | | asdf | 5000000 | +-------------+---------+ 10 rows in set (0.00 sec) 4. AFTER UPDATE mysql> CREATE TRIGGER after_update after update ON `xodimlar` for each row -> begin -> INSERT INTO log VALUES(current_user(), CONCAT('Update by', ' root', ' ', now())); - > end? Query OK, 0 rows affected (0.01 sec) mysql> UPDATE xodimlar SET ism='asdfghjk' WHERE xodim_id=11? Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT * FROM log? +----------------+-----------------------------------+ | user | status | +----------------+-----------------------------------+ | root@localhost | Update by root 2022-12-19 16:35:14 | +----------------+----------------------------- -----+ 1 row in set (0.00 sec) mysql> 5. BEFORE DELETE CREATE TRIGGER before_delete before update ON `xodimlar` for each row -> begin -> SIGNAL sqlstate '45000' SET message_text='NOT_ALLOWED'; -> end? Query OK, 0 rows affected (0.01 sec) 6. AFTER DELETE mysql> CREATE TRIGGER after_elete after delete ON `xodimlar` for each row -> begin -> INSERT INTO log VALUES(current_user(), CONCAT('Delete by', ' root', ' ', now())); - > end? Query OK, 0 rows affected (0.03 sec) mysql> DELETE FROM `xodimlar` WHERE xodim_id=9? Query OK, 1 row affected (0.01 sec) mysql> SELECT * FROM log? +----------------+------------------------------------+ | user | status | +----------------+------------------------------------+ | root@localhost | Update byroot 2022-12-19 16:35:14 | | root@localhost | Delete by root 2022-12-19 16:55:15 | +----------------+-------------------------- ----------+ 2 rows in set (0.00 sec) 4. Har bir talaba o’ziga berilgan predmet soha bo’yicha yaratgan MBni python dasturiga bo’glashi va ma’lumotlar bazasi yordamida oddiy intyerfyeys yaratish. Download 231.3 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling