Sql tilida index yaratish. Tasavvur, view yaratish va undan foydalanish
Download 350.21 Kb. Pdf ko'rish
|
SQL tilida INDEX yaratish
Funksya yaratish
mysql> Create function sotuvchilar() -> returns varchar(20) -> deterministic -> begin -> declare result VARCHAR(30) ; -> SET RESULT = 'sotuvchilar' ; -> RETURN (RESULT); -> end $$ Query OK, 0 rows affected (0.05 sec) mysql> select sotuvchilar() $$ +----------+ | sotuvchilar() | +----------+ | sotuvchilar | +----------+ 1 row in set (0.03 sec) use oziq_ovqa_savdo_dokoni $$ Database changed mysql> create table buyurtma -> ( id int auto_increment primary key, -> berilgan_vaqt date, -> yetib_borish_vaqti date, -> nomi text ) $$ Query OK, 0 rows affected (0.11 sec) mysql> create trigger j_vaqti before insert -> on -> buyurtma -> for each row -> begin -> set new.berilgan_vaqt=now(); -> set new.yetib_borish_vaqti=adddate(new.berilgan_vaqt, interval 1 day); -> end $$ Query OK, 0 rows affected (0.13 sec) Records: 4 Duplicates: 0 Warnings: 4 mysql> select * from buyurtma $$ +----+---------------+--------------------+-----------+ | id | berilgan_vaqt | yetib_borish_vaqti | nomi | +----+---------------+--------------------+-----------+ | 1 | 2022-12-14 | 2022-12-15 | Patir | | 2 | 2022-12-14 | 2022-12-15 | buxonka | | 3 | 2022-12-14 | 2022-12-15 | bolichka | | 4 | 2022-12-14 | 2022-12-15 | Oddiy non | +----+---------------+--------------------+-----------+ 4 rows in set (0.02 sec) mysql> show triggers\G $$ *************************** 1. row *************************** Trigger: j_vaqti Event: INSERT Table: buyurtma Statement: begin set new.berilgan_vaqt=now(); set new.yetib_borish_vaqti=adddate(new.berilgan_vaqt, interval 1 day); end Timing: BEFORE Created: NULL sql_mode: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBST ITUTION Definer: root@localhost character_set_client: latin1 collation_connection: latin1_swedish_ci Database Collation: latin1_swedish_ci 1 row in set (0.02 sec) Xulosa Men bu SQL tili orqali non markazi haqida dastur tuzdim kelajakda buni takomillashtirilsa non markazidagilar uchun qulaylik vaqtni tejash uchun judayam foydali bo’ladi degan umiddaman. |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling