Guruh Talaba Qabul qildi 652-21 Shokarimov Murodjon A. Dilshodov


Download 421.8 Kb.
Pdf ko'rish
bet2/3
Sana03.02.2023
Hajmi421.8 Kb.
#1150299
1   2   3
Bog'liq
Murodjon MB 3-dedline

 
 
 
 
 
 
 
 
 
 
 
 
 
 


Funksya yaratish 
mysql> Create function 
Texnik()
-> returns varchar(20)
-> deterministic
-> begin
-> declare result VARCHAR(30) ;
-> SET RESULT = 'Texnik' ;
-> RETURN (RESULT);
-> end $$
Query OK, 0 rows affected (0.05 sec)
mysql> select texnik() $$
+----------+
| texnik() |
+----------+
| Texnik |
+----------+
1 row in set (0.03 sec)
 


Trigger yaratish 
mysql>
use texnika_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.



Download 421.8 Kb.

Do'stlaringiz bilan baham:
1   2   3




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