Tayyorladi 712-21 guruh talabasi Inomova m aeroport bazasi Kodlari mysql> create database aereport
Download 1.04 Mb. Pdf ko'rish
|
2dedline1
Tayyorladi 712-21 guruh talabasi Inomova M Aeroport bazasi Kodlari mysql> create database aereport; Query OK, 1 row affected (0.00 sec) mysql> show databases; +-----------------------+ | Database | +-----------------------+ | information_schema | | aereport | | ehtiyot_qismlari | | idora | | kutubxona | | lombard | | mashinalar | | masulyatni_taqsimlash | | mehmonxona | | mysql | | notarial_idora | | sayohat_kompaniyasi | | sugurta | | test | +-----------------------+ 14 rows in set (0.01 sec) mysql> use aereport; Database changedmysql> create table xodimlar( -> id int auto_increment primary key, -> ism varchar(30), -> familya varchar(30), -> yli date, -> manzil varchar(40), -> telefoni varchar(20), -> jins char(20)); Query OK, 0 rows affected (0.03 sec) mysql> create table chipta( -> id int auto_increment primary key, -> yolovchi_nomi char(30), -> pasport_malumotlari varchar(50), -> parvoz_raqami int , -> chiptalar_soni int, -> imtiyozlar_mavjudligi varchar(30), -> bagaj char(30), -> narxi int); Query OK, 0 rows affected (0.02 sec) mysql> create table samolyot( -> id int auto_increment primary key, -> xona int , -> yili date, -> urindiqlar_soni int, -> yuk_hajmi int); Query OK, 0 rows affected (0.01 sec) mysql> create table samolyot_brigadasi( -> id int auto_increment primary key, -> brigada_raqami int, -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4 mysql> create table samolyot_brigadasi( -> id int auto_increment primary key, -> brigada_raqami int); Query OK, 0 rows affected (0.01 sec) mysql> alter table samolyot_brigadasi -> add column xodimlar_id int, -> add foreign key (xodimlar_id) references xodimlar(id); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table samolyot_brigadasi -> add column samolyot_id int, -> add foreign key (samolyot_id) references samolyot(id); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> create table jadvali( -> id int auto_increment primary key, -> chiqish_sanasi date, -> yuli varchar(30), -> borar_joyi varchar(30), -> marshrut varchar(30)); Query OK, 0 rows affected (0.01 sec) mysql> alter table jadvali -> add column samolyot_id int, -> add foreign key (samolyot_id) references samolyot(id); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table jadvali -> add column chipta_id int, -> add foreign key (chipta_id) references chipta(id); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show tables; +--------------------+ | Tables_in_aereport | +--------------------+ | chipta | | jadvali | | samolyot | | samolyot_brigadasi | | xodimlar | +--------------------+ 5 rows in set (0.00 sec) mysql> desc chipta; +-----------------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | yolovchi_nomi | char(30) | YES | | NULL | | | pasport_malumotlari | varchar(50) | YES | | NULL | | | parvoz_raqami | int(11) | YES | | NULL | | | chiptalar_soni | int(11) | YES | | NULL | | | imtiyozlar_mavjudligi | varchar(30) | YES | | NULL | | | bagaj | char(30) | YES | | NULL | | | narxi | int(11) | YES | | NULL | | +-----------------------+-------------+------+-----+---------+----------------+ 8 rows in set (0.01 sec) mysql> desc samolyot; +-----------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | xona | int(11) | YES | | NULL | | | yili | date | YES | | NULL | | | urindiqlar_soni | int(11) | YES | | NULL | | | yuk_hajmi | int(11) | YES | | NULL | | +-----------------+---------+------+-----+---------+----------------+ 5 rows in set (0.01 sec) mysql> desc xodimlar; +----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | ism | varchar(30) | YES | | NULL | | | familya | varchar(30) | YES | | NULL | | | yli | date | YES | | NULL | | | manzil | varchar(40) | YES | | NULL | | | telefoni | varchar(20) | YES | | NULL | | | jins | char(20) | YES | | NULL | | +----------+-------------+------+-----+---------+----------------+ 7 rows in set (0.01 sec) mysql> desc jadvali; +----------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | chiqish_sanasi | date | YES | | NULL | | | yuli | varchar(30) | YES | | NULL | | | borar_joyi | varchar(30) | YES | | NULL | | | marshrut | varchar(30) | YES | | NULL | | | samolyot_id | int(11) | YES | MUL | NULL | | | chipta_id | int(11) | YES | MUL | NULL | | +----------------+-------------+------+-----+---------+----------------+ 7 rows in set (0.01 sec) mysql> desc samolyot_brigadasi; +----------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | brigada_raqami | int(11) | YES | | NULL | | | xodimlar_id | int(11) | YES | MUL | NULL | | | samolyot_id | int(11) | YES | MUL | NULL | | +----------------+---------+------+-----+---------+----------------+ 4 rows in set (0.01 sec) mysql> INSERT INTO xodimlar (ism, familya, yli, manzil, telefoni, jins) -> VALUES ('John', 'Doe', '1990-01-01', '123 Main Street, City', '+1234567890', 'Male'), -> ('Jane', 'Doe', '1992-05-15', '456 Oak Avenue, Town', '+9876543210', 'Female'), -> ('Alice', 'Smith', '1988-11-30', '789 Pine Road, Village', '+1122334455', 'Female'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> INSERT INTO samolyot (xona, yili, urindiqlar_soni, yuk_hajmi) -> VALUES (1, '2020-01-01', 50, 5000), -> (2, '2019-05-15', 30, 3000), -> (3, '2022-11-30', 40, 4000); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> INSERT INTO samolyot_brigadasi (brigada_raqami, xodimlar_id, samolyot_id) -> VALUES (1, 101, 201), -> (2, 102, 202), -> (3, 103, 203); ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`aereport`.`samolyot_brigadasi`, CONSTRAINT `samolyot_brigadasi_ibfk_1` FOREIGN KEY (`xodimlar_id`) REFERENCES `xodimlar` (`id`)) mysql> INSERT INTO samolyot_brigadasi (brigada_raqami, xodimlar_id, samolyot_id) -> VALUES (1, 1, 1); Query OK, 1 row affected (0.01 sec) mysql> INSERT INTO samolyot_brigadasi (brigada_raqami, xodimlar_id, samolyot_id) -> VALUES (1, 2, 3); Query OK, 1 row affected (0.01 sec) mysql> select*from samolyot; +----+------+------------+-----------------+-----------+ | id | xona | yili | urindiqlar_soni | yuk_hajmi | +----+------+------------+-----------------+-----------+ | 1 | 1 | 2020-01-01 | 50 | 5000 | | 2 | 2 | 2019-05-15 | 30 | 3000 | | 3 | 3 | 2022-11-30 | 40 | 4000 | +----+------+------------+-----------------+-----------+ 3 rows in set (0.00 sec) mysql> select*from xodimlar; +----+-------+---------+------------+------------------------+-------------+--------+ | id | ism | familya | yli | manzil | telefoni | jins | +----+-------+---------+------------+------------------------+-------------+--------+ | 1 | John | Doe | 1990-01-01 | 123 Main Street, City | +1234567890 | Male | | 2 | Jane | Doe | 1992-05-15 | 456 Oak Avenue, Town | +9876543210 | Female | | 3 | Alice | Smith | 1988-11-30 | 789 Pine Road, Village | +1122334455 | Female | +----+-------+---------+------------+------------------------+-------------+--------+ 3 rows in set (0.00 sec) mysql> select*from samolyot_brigadasi; +----+----------------+-------------+-------------+ | id | brigada_raqami | xodimlar_id | samolyot_id | +----+----------------+-------------+-------------+ | 4 | 1 | 1 | 1 | | 5 | 1 | 2 | 3 | +----+----------------+-------------+-------------+ 2 rows in set (0.00 sec) mysql> SELECT -> samolyot.id AS samolyot_id, -> samolyot.xona, -> samolyot.yili, -> samolyot.urindiqlar_soni, -> samolyot.yuk_hajmi, -> xodimlar.id AS xodim_id, -> xodimlar.ism, -> xodimlar.familya, -> xodimlar.yli AS xodim_yili, -> xodimlar.manzil, -> xodimlar.telefoni, -> xodimlar.jins, -> samolyot_brigadasi.id AS brigada_id, -> samolyot_brigadasi.brigada_raqami -> FROM -> samolyot_brigadasi -> JOIN samolyot ON samolyot_brigadasi.samolyot_id = samolyot.id -> JOIN xodimlar ON samolyot_brigadasi.xodimlar_id = xodimlar.id; +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+--------+------------+----------------+ | samolyot_id | xona | yili | urindiqlar_soni | yuk_hajmi | xodim_id | ism | familya | xodim_yili | manzil | telefoni | jins | brigada_id | brigada_raqami | +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+--------+------------+----------------+ | 1 | 1 | 2020-01-01 | 50 | 5000 | 1 | John | Doe | 1990-01-01 | 123 Main Street, City | +1234567890 | Male | 4 | 1 | | 3 | 3 | 2022-11-30 | 40 | 4000 | 2 | Jane | Doe | 1992-05-15 | 456 Oak Avenue, Town | +9876543210 | Female | 5 | 1 | +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+--------+------------+----------------+ 2 rows in set (0.00 sec) mysql> SELECT -> samolyot.id AS samolyot_id, -> samolyot.xona, -> samolyot.yili, -> samolyot.urindiqlar_soni, -> samolyot.yuk_hajmi, -> xodimlar.id AS xodim_id, -> xodimlar.ism, -> xodimlar.familya, -> xodimlar.yli AS xodim_yili, -> xodimlar.manzil, -> xodimlar.telefoni, -> xodimlar.jins, -> samolyot_brigadasi.id AS brigada_id, -> samolyot_brigadasi.brigada_raqami -> FROM -> samolyot_brigadasi -> JOIN samolyot ON samolyot_brigadasi.samolyot_id = samolyot.id -> JOIN xodimlar ON samolyot_brigadasi.xodimlar_id = xodimlar.id; +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+--------+------------+----------------+ | samolyot_id | xona | yili | urindiqlar_soni | yuk_hajmi | xodim_id | ism | familya | xodim_yili | manzil | telefoni | jins | brigada_id | brigada_raqami | +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+--------+------------+----------------+ | 1 | 1 | 2020-01-01 | 50 | 5000 | 1 | John | Doe | 1990-01-01 | 123 Main Street, City | +1234567890 | Male | 4 | 1 | | 3 | 3 | 2022-11-30 | 40 | 4000 | 2 | Jane | Doe | 1992-05-15 | 456 Oak Avenue, Town | +9876543210 | Female | 5 | 1 | +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+--------+------------+----------------+ 2 rows in set (0.00 sec) mysql> SELECT -> samolyot.id AS samolyot_id, -> samolyot.xona, -> samolyot.yili, -> samolyot.urindiqlar_soni, -> samolyot.yuk_hajmi, -> xodimlar.id AS xodim_id, -> xodimlar.ism, -> xodimlar.familya, -> xodimlar.yli AS xodim_yili, -> xodimlar.manzil, -> xodimlar.telefoni, -> xodimlar.jins, -> samolyot_brigadasi.id AS brigada_id, -> samolyot_brigadasi.brigada_raqami -> FROM -> samolyot_brigadasi -> JOIN samolyot ON samolyot_brigadasi.samolyot_id = samolyot.id -> JOIN xodimlar ON samolyot_brigadasi.xodimlar_id = xodimlar.id -> WHERE -> samolyot.yili = '2020-01-01'; +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+------+------------+----------------+ | samolyot_id | xona | yili | urindiqlar_soni | yuk_hajmi | xodim_id | ism | familya | xodim_yili | manzil | telefoni | jins | brigada_id | brigada_raqami | +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+------+------------+----------------+ | 1 | 1 | 2020-01-01 | 50 | 5000 | 1 | John | Doe | 1990-01-01 | 123 Main Street, City | +1234567890 | Male | 4 | 1 | +-------------+------+------------+-----------------+-----------+----------+------+---------+------------+-----------------------+-- -----------+------+------------+----------------+ 1 row in set (0.00 sec) Download 1.04 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling