Вы находитесь на странице: 1из 7

mysql> create database ins;

Query OK, 1 row affected (0.03 sec)


mysql> use ins;
Database changed
mysql> create table peron
-> (driver_id varchar(25) primary key,
-> name varchar(25),
-> address varchar(25));
Query OK, 0 rows affected (0.06 sec)
mysql> create table car
-> (regno varchar(25) primary key,
-> model varchar(25),
-> year int(10));
Query OK, 0 rows affected (0.06 sec)
mysql> create table accident
-> (report_no int(10) primary key,
-> acc_date date,
-> location varchar(25));
Query OK, 0 rows affected (0.06 sec)
mysql> create table owns
-> (driver_id varchar(20) references person(driver_id),
-> regno varchar(20) references car(regno));
Query OK, 0 rows affected (0.06 sec)
mysql> create table participated
-> (driver_id varchar(20) references person(Driver_id),
-> regno varchar(20) references car(regno),
-> report_no int(9) references accident(report_no),
-> damageamt int(15));
Query OK, 0 rows affected (0.08 sec)
mysql> exit
mysql> insert into person
-> values('d1','sathish','bangalore');
ERROR 1046 (3D000): No database selected
mysql> use ins;
Database changed
mysql> insert into person
-> values('d1','sathish','bangalore');
ERROR 1146 (42S02): Table 'ins.person' doesn't exist
mysql> show databases
-> ;
+--------------------+
| Database
|
+--------------------+
| information_schema |
| ins
|
| mysql
|
| prg
|
| test
|
+--------------------+
5 rows in set (0.00 sec)
mysql> show tables;
+---------------+
| Tables_in_ins |

+---------------+
| accident
|
| car
|
| owns
|
| participated |
| peron
|
+---------------+
5 rows in set (0.02 sec)
mysql> insert into peron
-> values('d1','sathish','bangalore');
Query OK, 1 row affected (0.03 sec)
mysql> insert into peron
-> values('d2','mahesh','mangalore');
Query OK, 1 row affected (0.02 sec)
mysql> insert into peron
-> values('d3','anil','mumbai');
Query OK, 1 row affected (0.02 sec)
mysql> insert into peron
-> values('d4','vachan','pune');
Query OK, 1 row affected (0.03 sec)
mysql> insert into peron
-> values('d4','yashish','lucknow');
ERROR 1062 (23000): Duplicate entry 'd4' for key 1
mysql> insert into peron
-> values('d5','vachan','pune');
Query OK, 1 row affected (0.03 sec)
mysql> select *from peron;
+-----------+---------+-----------+
| driver_id | name
| address |
+-----------+---------+-----------+
| d1
| sathish | bangalore |
| d2
| mahesh | mangalore |
| d3
| anil
| mumbai
|
| d4
| vachan | pune
|
| d5
| vachan | pune
|
+-----------+---------+-----------+
5 rows in set (0.02 sec)
mysql> insert into car
-> values('c1','maruti',2000);
Query OK, 1 row affected (0.02 sec)
mysql> insert into car
-> values('c2','honda',2005);
Query OK, 1 row affected (0.03 sec)
mysql> insert into car
-> values('c3','swift',2008);
Query OK, 1 row affected (0.03 sec)
mysql> insert into car
-> values('c4','ferrari',2010);
Query OK, 1 row affected (0.01 sec)

mysql> insert into car


-> values('c5','indigo',2011);
Query OK, 1 row affected (0.03 sec)
mysql> select *from car;
+-------+---------+------+
| regno | model | year |
+-------+---------+------+
| c1
| maruti | 2000 |
| c2
| honda | 2005 |
| c3
| swift | 2008 |
| c4
| ferrari | 2010 |
| c5
| indigo | 2011 |
+-------+---------+------+
5 rows in set (0.00 sec)
mysql> insert into accident
-> values(11,'2008/09/06','amristar);
'> ';
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 2
mysql>
mysql> insert into accident
-> values(11,'2008/09/06','amristar');
Query OK, 1 row affected (0.03 sec)
mysql> insert into accident
-> values(12,'2008/12/16','goa');
Query OK, 1 row affected (0.01 sec)
mysql> insert into accident
-> values(12,'2009/05/18','kerala');
ERROR 1062 (23000): Duplicate entry '12' for key 1
mysql> insert into accident
-> values(13,'2009/05/18','kerala');
Query OK, 1 row affected (0.03 sec)
mysql> insert into accident
-> values(14,'2009/08/23','chennai');
Query OK, 1 row affected (0.03 sec)
mysql> insert into accident
-> values(14,'2010/12/26','west bengal');
ERROR 1062 (23000): Duplicate entry '14' for key 1
mysql> insert into accident
-> values(15,'2010/12/26','west bengal');
Query OK, 1 row affected (0.02 sec)
mysql> select *from accident;
+-----------+------------+-------------+
| report_no | acc_date | location
|
+-----------+------------+-------------+
|
11 | 2008-09-06 | amristar
|
|
12 | 2008-12-16 | goa
|
|
13 | 2009-05-18 | kerala
|
|
14 | 2009-08-23 | chennai
|
|
15 | 2010-12-26 | west bengal |
+-----------+------------+-------------+
5 rows in set (0.00 sec)

mysql> insert into owns


-> values('d2','c3');
Query OK, 1 row affected (0.03 sec)
mysql> insert into owns
-> values('d3','c2');
Query OK, 1 row affected (0.03 sec)
mysql> insert into owns
-> values('d1','c5');
Query OK, 1 row affected (0.01 sec)
mysql> insert into owns
-> values('d5','c4');
Query OK, 1 row affected (0.02 sec)
mysql> insert into owns
-> values('d4','c1');
Query OK, 1 row affected (0.01 sec)
mysql> select *fromowns;
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 'fromo
wns' at line 1
mysql> select *from owns;
+-----------+-------+
| driver_id | regno |
+-----------+-------+
| d2
| c3
|
| d3
| c2
|
| d1
| c5
|
| d5
| c4
|
| d4
| c1
|
+-----------+-------+
5 rows in set (0.00 sec)
mysql> insert into participated
-> values('d3','c4',15,20000);
Query OK, 1 row affected (0.03 sec)
mysql> insert into participated
-> values('d2','c5',13,22500);
Query OK, 1 row affected (0.01 sec)
mysql> insert into participated
-> values('d1','c2',11,18500);
Query OK, 1 row affected (0.02 sec)
mysql> insert into participated
-> values('d5','c3',12,13500);
Query OK, 1 row affected (0.03 sec)
mysql> insert into participated
-> values('d4','c1',14,11000);
Query OK, 1 row affected (0.03 sec)
mysql> select *from participated;
+-----------+-------+-----------+-----------+
| driver_id | regno | report_no | damageamt |

+-----------+-------+-----------+-----------+
| d3
| c4
|
15 |
20000 |
| d2
| c5
|
13 |
22500 |
| d1
| c2
|
11 |
18500 |
| d5
| c3
|
12 |
13500 |
| d4
| c1
|
14 |
11000 |
+-----------+-------+-----------+-----------+
5 rows in set (0.00 sec)
mysql> exit
mysql> use ins;
Database changed
mysql> select *from participated;
+-----------+-------+-----------+-----------+
| driver_id | regno | report_no | damageamt |
+-----------+-------+-----------+-----------+
| d3
| c4
|
15 |
20000 |
| d2
| c5
|
13 |
22500 |
| d1
| c2
|
11 |
18500 |
| d5
| c3
|
12 |
13500 |
| d4
| c1
|
14 |
11000 |
+-----------+-------+-----------+-----------+
5 rows in set (0.00 sec)
mysql> update participated
-> set damageamt=25000
-> where regno='c2' and report_no=11;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select *from participated;
+-----------+-------+-----------+-----------+
| driver_id | regno | report_no | damageamt |
+-----------+-------+-----------+-----------+
| d3
| c4
|
15 |
20000 |
| d2
| c5
|
13 |
22500 |
| d1
| c2
|
11 |
25000 |
| d5
| c3
|
12 |
13500 |
| d4
| c1
|
14 |
11000 |
+-----------+-------+-----------+-----------+
5 rows in set (0.00 sec)
mysql> insert into accident
-> values(16,'2005/07/07','bangalore');
Query OK, 1 row affected (0.02 sec)
mysql> insert into participated
-> values('d3','c5',16,13400);
Query OK, 1 row affected (0.03 sec)
mysql> select count(driverid) from participated as P,accident as A
-> where A.report_no=P.report_no and A.date like '2008%';
ERROR 1054 (42S22): Unknown column 'driverid' in 'field list'
mysql> select count(driver_id) from participated as P,accident as A
-> where A.report_no=P.report_no and A.date like '2008%';
ERROR 1054 (42S22): Unknown column 'A.date' in 'where clause'
mysql> select count(driverid) from participated as P,accident as A
-> where A.report_no=P.report_no and A.acc_date like '2008%';
ERROR 1054 (42S22): Unknown column 'driverid' in 'field list'
mysql> select count(driver_id) from participated as P,accident as A

-> where A.report_no=P.report_no and A.acc_date like '2008%';


+------------------+
| count(driver_id) |
+------------------+
|
2 |
+------------------+
1 row in set (0.02 sec)
mysql> select count(report_no) from participated as P,car as C
-> where C.regno=P.regno and C.model='maruti';
+------------------+
| count(report_no) |
+------------------+
|
1 |
+------------------+
1 row in set (0.00 sec)
mysql> select *from peron;
+-----------+---------+-----------+
| driver_id | name
| address |
+-----------+---------+-----------+
| d1
| sathish | bangalore |
| d2
| mahesh | mangalore |
| d3
| anil
| mumbai
|
| d4
| vachan | pune
|
| d5
| vachan | pune
|
+-----------+---------+-----------+
5 rows in set (0.00 sec)
mysql> exit
mysql> desc accident;
+--------------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| reportnumber | int(12)
| NO | PRI |
|
|
| acc_date
| date
| YES |
| NULL
|
|
| location
| varchar(25) | YES |
| NULL
|
|
+--------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> desc car;
+-------+-------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| regno | varchar(25) | NO | PRI |
|
|
| model | varchar(25) | YES |
| NULL
|
|
| year | int(12)
| YES |
| NULL
|
|
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
mysql> desc peron;
ERROR 1146 (42S02): Table 'prg.peron' doesn't exist
mysql> desc person;
+----------+-------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| driverid | varchar(25) | NO | PRI |
|
|
| name
| varchar(25) | YES |
| NULL
|
|
| address | varchar(25) | YES |
| NULL
|
|
+----------+-------------+------+-----+---------+-------+

3 rows in set (0.05 sec)


mysql> exit