Experiment 3
To create database, table and to make use of them
*Create database of your name and then use it to
mysql> create database shrikant;
Query OK, 1 row affected (0.01 sec)
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sakila |
| shrikant
| sys |
| world |
+--------------------+
7 rows in set (0.00 sec)
mysql> use shrikant;
Database changed
A) Create teachers tables with following attributes id, tname, taddress , salary
and hiredate and insert atleast 10 records into it.
mysql> create table teacher_table(
-> id int,
-> tname varchar(45),
-> taddress varchar(55),
-> salary bigint,
-> hiredate date);
Query OK, 0 rows affected (0.03 sec)
insert into teacher_table values
-> (2520,'Arjun','Latur',20000,'2016-06-10'),
-> (2521,'Navnath','Singapore',21000,'2015-05-04'),
-> (2522,'Sahil','Thailand',25000,'2017-02-25'),
-> (2523,'Ahad','USA',50000,'2018-04-18'),
-> (2524,'Yogesh','Omerga',30000,'2020-09-21'),
-> (2525,'Atul','Phillipines',80000,'2021-08-12'),
-> (2526,'Rohit','London',10000,'2021-03-15'),
-> (2527,'Sai','Africa',2000,'2022-05-14'),
-> (2528,'Priya','Wadgaon',50000,'2023-05-16'),
-> (2529,'Rutuja','Tuljapur',1000,'2023-05-16'),
-> (2530,'UDAHV','MUMBAI',7000,'2012-12-23');
Query OK, 11 rows affected (0.01 sec)
Records: 11 Duplicates: 0 Warnings: 0
B) Create students table along with the attributes rollno., sname, saddress, dob
and
phoneno. and insert atleast 10 records into it.
mysql> create table student(
-> rollno int,
-> sname varchar(45),
-> saddress varchar(50),
-> DOB date,
-> PhoneNo bigint);
Query OK, 0 rows affected (0.05 sec)
mysql> insert into student values
-> (1,'Varad','Hongkong','2000-10-21',123456),
-> (8,'Dildar','Pohner','2004-02-18',789456),
-> (12,'Nirmiti','Africa','2003-07-14',852369),
-> (23,'Apeksha','Tugaon','2003-03-20',741258),
-> (31,'Sohel','Bembli','2002-04-25',935988),
-> (33,'Kisan','Bembli','1998-05-30',456123),
-> (43,'Dora','Rajuri','2002-05-20',751071),
-> (50,'Don','Pune','2001-08-25',546987),
-> (55,'Tumbesh','Barshi','1999-08-10',785123),
-> (60,'Rambha','Swarglog','2000-01-01',741236);
Query OK, 10 rows affected (0.02 sec)
Records: 10 Duplicates: 0 Warnings: 0
1) write a query to show all the rows of the tables.
mysql> select * from student;
+--------+---------+----------+------------+---------+
| rollno | sname | saddress | DOB | PhoneNo |
+--------+---------+----------+------------+---------+
| 1 | Varad | Hongkong | 2000-10-21 | 123456 |
| 8 | Dildar | Pohner | 2004-02-18 | 789456 |
| 12 | Nirmiti | Africa | 2003-07-14 | 852369 |
| 23 | Apeksha | Tugaon | 2003-03-20 | 741258 |
| 31 | Sohel | Bembli | 2002-04-25 | 935988 |
| 33 | Kisan | Bembli | 1998-05-30 | 456123 |
| 43 | Dora | Rajuri | 2002-05-20 | 751071 |
| 50 | Don | Pune | 2001-08-25 | 546987 |
| 55 | Tumbesh | Barshi | 1999-08-10 | 785123 |
| 60 | Rambha | Swarglog | 2000-01-01 | 741236 |
+--------+---------+----------+------------+---------+
10 rows in set (0.00 sec)
mysql> select * from teacher_table;
+------+---------+-------------+--------+------------+
| id | tname | taddress | salary | hiredate |
+------+---------+-------------+--------+------------+
| 2520 | Arjun | Latur | 25000 | 2016-06-10 |
| 2521 | Navnath | Singapore | 26000 | 2015-05-04 |
| 2522 | Sahil | Thailand | 30000 | 2017-02-25 |
| 2523 | Ahad | USA | 55000 | 2018-04-18 |
| 2524 | Yogesh | Omerga | 35000 | 2020-09-21 |
| 2525 | Atul | Phillipines | 85000 | 2021-08-12 |
| 2526 | Rohit | London | 15000 | 2021-03-15 |
| 2527 | Sai | Africa | 7000 | 2022-05-14 |
| 2528 | Priya | Wadgaon | 55000 | 2023-05-16 |
| 2529 | Rutuja | Tuljapur | 6000 | 2023-05-16 |
| 2530 | UDAHV | MUMBAI | 12000 | 2012-12-23 |
+------+---------+-------------+--------+------------+
11 rows in set (0.00 sec)
2) write the query to print name and phone numbers from students table.
mysql> select sname,phoneno from student;
+---------+---------+
| sname | phoneno |
+---------+---------+
| Varad | 123456 |
| Dildar | 789456 |
| Nirmiti | 852369 |
| Apeksha | 741258 |
| Sohel | 935988 |
| Kisan | 456123 |
| Dora | 751071 |
| Don | 546987 |
| Tumbesh | 785123 |
| Rambha | 741236 |
+---------+---------+
10 rows in set (0.00 sec)
3) write a query to print tid, tname, and salary from teachers
mysql> select id,tname,salary from teacher_table;
+------+---------+--------+
| id | tname | salary |
+------+---------+--------+
| 2520 | Arjun | 25000 |
| 2521 | Navnath | 26000 |
| 2522 | Sahil | 30000 |
| 2523 | Ahad | 55000 |
| 2524 | Yogesh | 35000 |
| 2525 | Atul | 85000 |
| 2526 | Rohit | 15000 |
| 2527 | Sai | 7000 |
| 2528 | Priya | 55000 |
| 2529 | Rutuja | 6000 |
| 2530 | UDAHV | 12000 |
+------+---------+--------+
11 rows in set (0.00 sec)