Dastur codlari
mysql> CREATE DATABASE vokzal;
Query OK, 1 row affected (0.01 sec)
mysql> use vokzal;
Database changed
mysql> create table yolovchi (
-> id
int PRIMARY KEY,
-> ism varchar(200),
-> yosh int,
-> jinsi ENUM('erkak', 'ayol'),
-> telefon char(10));
Query OK, 0 rows affected (0.05 sec)
mysql> create table reys(
-> id int PRIMARY KEY,
-> nomi varchar(200),
-> vokzal_id int,
-> chiqish_sana DATE,
-> FOREIGN KEY (vokzal_id) references vokzal(id));
ERROR 1005 (HY000): Can't create table 'vokzal.reys' (errno: 150)
mysql> create table reys(
-> id int PRIMARY KEY,
-> nomi varchar(200),
-> vokzal_id int,
-> chiqish_sana DATE,
-> FOREIGN KEY (vokzal_id) REFERENCES vokzal(id));
ERROR 1005 (HY000): Can't create table 'vokzal.reys' (errno: 150)
mysql> CREATE TABLE vokzal (
->
id INT PRIMARY KEY,
-> nomi VARCHAR(255)
-> );
Query OK, 0 rows affected (0.03 sec)
mysql> create table reys(
-> id int PRIMARY KEY,
-> nomi varchar(200),
-> vokzal_id int,
-> chiqish_sana DATE,
-> FOREIGN KEY (vokzal_id) REFERENCES vokzal(id));
Query OK, 0 rows affected (0.02 sec)
mysql> CREATE TABLE poyezd (
-> id INT PRIMARY KEY,
-> nomi VARCHAR(255),
-> yurish_vaqt TIME,
-> tashish_vaqt TIME
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> alter table
poyezd add sanasi Date;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table
poyezd drop column sanasi;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desk poyezd;
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 'desk poyezd' at line 1
mysql> desc poyezd;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| nomi | varchar(255) | YES | | NULL | |
| yurish_vaqt | time | YES | | NULL | |
| tashish_vaqt | time | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
4 rows in set (0.02 sec)
mysql> INSERT INTO vokzal (id, nomi)
-> VALUES (1, 'Toshkent'),
-> (2, 'Samarkand'),
-> (3, 'Bukhara');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> INSERT INTO reys (id, nomi, vokzal_id, chiqish_sana)
-> VALUES (1, 'Toshkent-Samarkand', 2, '2023-10-23'),