1-topshiriq Mohiyat aloqa diagrammasi

1-topshiriq
Mohiyat aloqa diagrammasi
Mavzu : avtosalon
1.Avtosalon bazani yaratib olamiz
mysql> create database avtosalon;
Query OK, 1 row affected (0.01 sec)
Natijasi:
2.Yaratgan bazani ko’rib va uni tanlab olamiz
So’rov: show databases;
So’rov:
mysql> use avtosalon;
Database changed
Natijasi:
3.create table table name buyrugi ostida jadvallarimizni yaratib
olamiz:
So’rov:
mysql> create table xodim(
-> id int auto_increment primary key,
-> ism char(50),
-> fam char(50),
-> ota_ismi char(50),
-> tajribasi char(50),
-> ish_haqi varchar(50));
Query OK, 0 rows affected (0.02 sec)
mysql> create table markasi(
-> id int auto_increment primary key,
-> tovar_nomi char(50),
-> davlat char(50),
-> zavod_ishlab_chiqaruvchi char(50),
-> manzili varchar(50));
Query OK, 0 rows affected (0.01 sec)
mysql> create table avtomobil(
-> id int auto_increment primary key,
-> nomi char(50),
-> tovar varchar(50),
-> yili_chiqqan date,
-> rangi varchar(20),
-> narxi int);
Query OK, 0 rows affected (0.02 sec)
mysql> alter table avtomobil
-> add column markasi_id int,
-> add foreign key (markasi_id) references markasi(id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> create table sotish(
-> id int auto_increment primary key,
-> sana date,
-> vaqti varchar(50));
Query OK, 0 rows affected (0.02 sec)
mysql> alter table sotish
-> add column avtomobil_id int,
-> add foreign key (avtomobil_id) references avtomobil(id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sotish
-> add column xodim_id int,
-> add foreign key (xodim_id) references xodim(id);
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> create table xaridor(
-> id int auto_increment primary key,
-> ism char(50),
-> fam char(50),
-> ota_ismi char(50),
-> pasport_malumotlari varchar(50),
-> manzili varchar(50),
-> yoshi varchar(50),
-> jinsi varchar(30));
Query OK, 0 rows affected (0.02 sec)
mysql> alter table sotish
-> add column xaridor_id int,
-> add foreign key (xaridor_id) references xaridor(id);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0
Natijasi:
4.insert into buyrug’i asosida malumotlar qushamiz
So’rov
mysql> INSERT INTO xaridor (ism, fam, ota_ismi,
pasport_malumotlari, manzili, yoshi, jinsi)
-> VALUES ('John', 'Doe', 'Doe Sr.', 'AB123456', '123 Main
St', '30', 'Male'),
-> ('Alice', 'Smith', 'Smith Sr.', 'CD987654', '456 Elm St',
'28', 'Female');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO markasi (tovar_nomi, davlat,
zavod_ishlab_chiqaruvchi, manzili)
-> VALUES ('Toyota', 'Japan', 'Toyota Motors', 'Tokyo'),
-> ('BMW', 'Germany', 'BMW AG', 'Munich');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO avtomobil (nomi, tovar, yili_chiqqan,
rangi, narxi, markasi_id)
-> VALUES ('Corolla', 'Toyota', '2020-01-01', 'Red', 25000,
1),
-> ('X5', 'BMW', '2019-12-01', 'Black', 35000, 2);
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO xodim (ism, fam, ota_ismi, tajribasi,
ish_haqi)
-> VALUES ('James', 'Smith', 'Smith Sr.', '10 years',
'Manager'),
-> ('Emily', 'Johnson', 'Johnson Sr.', '8 years',
'Supervisor');
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> INSERT INTO sotish (sana, vaqti, avtomobil_id,
xodim_id, xaridor_id)
-> VALUES
-> ('2023-11-28', 'Morning', 1, 1, 1),
-> ('2023-11-29', 'Afternoon', 2, 2, 2);
Query OK, 2 rows affected (0.00 sec)
Natijasi:
So’rov:
mysql> INSERT INTO mehmonxona (nomi, mamlakat, shahar,
manzil, orindiqlar_soni, mexmonxona_turi)
-> VALUES ('Hotel ABC', 'USA', 'New York', '123 Main St',
'100', 'Luxury');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO sayyohlik_guruhi (ism, chiqish_sanasi,
borar_sanasi, safari, sayyohlar_soni)
-> VALUES ('Example Group', '2023-11-27', '2023-12-10',
'Europe Tour', 15);
Query OK, 1 row affected (0.00 sec)
Natijasi:
5.Malumotlar ustida amallar
So’rov:
mysql> select*from ekskursiyalar where id = 1;
Natijasi:
So’rov mysql> select*from ekskursiyalar where id=1 and
narxi=50;
Natijasi:
So’rov mysql> select*from ekskursiyalar where id=1 or
narxi=40;
Natijasi:
So’rov mysql> select*from ekskursiyalar where not id = 2;
Natijasi:
6.Malumotlarni saralash
So’rov mysql> select*from ekskursiyalar order by(narxi);
Natijasi:
7.Malumotlarni o’chirish
So’rov mysql> delete from ekskursiyalar where id = 1;
Query OK, 1 row affected (0.00 sec)
Natijasi:
8.Malumotlarni o’zgartirish
So’rov
mysql> UPDATE ekskursiyalar SET narxi = '60' WHERE id =
2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Natijasi:
9.Jadvallarni o’chirish
So’rov mysql> drop table ekskursiyalar;
Query OK, 0 rows affected (0.00 sec)
Natijasi:
10.Jadval ustunlarini o’zgartirish
So’rov mysql> ALTER TABLE sayyohlar
-> ADD COLUMN manzillar varchar(50) AFTER
pasport_malumotlari,
-> DROP COLUMN jins;
Query OK, 2 rows affected (0.03 sec)
Records: 2 Duplicates: 0 Warnings: 0
Natijasi:
|