0% found this document useful (0 votes)
22 views

Lab Program 2

The document describes creating and manipulating a database table called client_master. It includes creating the table, inserting records, selecting records, creating new tables from the original, updating and modifying the structure of the original table.

Uploaded by

Abdurahman Sal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lab Program 2

The document describes creating and manipulating a database table called client_master. It includes creating the table, inserting records, selecting records, creating new tables from the original, updating and modifying the structure of the original table.

Uploaded by

Abdurahman Sal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

2) Create a table client_master with the following fields.

Column_name Data Type Others


Client_no Varchar(6) Primary key

Name Varchar(20) Not null


Address Varchar(25)

City Varchar(20)
Pincode Decimal(6)

State Varchar(20)
Bal_due Decimal(7,2) Not null

create table client_master


-> (client_no varchar(6) primary key,
-> cname varchar(20) not null,
-> address varchar(25),
-> city varchar(20),
-> pin decimal(6),
-> state varchar(20),
-> bal_due decimal(7,2) not null);

insert into client_master


values('c01001','ponnu','pandeshwar','mangalore','575001','karnataka',500);

insert into client_master values('c01002','mukesh','thalangara','ksd','575002','kerala',300);

insert into client_master values('c01003','siddi','baga','bagal','575067','goa',400);

insert into client_master


values('c01004','aswanth','dongri','mumbai','575063','maharashtra',600);

insert into client_master values('c01005','akash','manali','haryana','575063','himacahl


pradesh',1000);

insert into client_master


values('c01006','sidharth','pumpwell','mangalore','575002','karnataka',650);

insert into client_master values('c01007','manoj','tirur','malappuram','671122','kerala',900);

insert into client_master values('c01008','arjun','church


road','bangalore','67567','karnataka',1500);
insert into client_master values('c01009','abhijith','koyilandi','calicut','675784','kerala',1200);

insert into client_master values('c01010','vishnu','raman


nagar','hyderabad','675789','telangana',2000);

Execute the following queries


a) Describe the structure of client_master.

describe client_master;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| client_no | varchar(6) | NO | PRI | NULL | |
| cname | varchar(20) | NO | | NULL | |
| address | varchar(25) | YES | | NULL | |
| city | varchar(20) | YES | | NULL | |
| pin | decimal(6,0) | YES | | NULL | |
| state | varchar(20) | YES | | NULL | |
| bal_due | decimal(7,2) | NO | | NULL | |
+-----------+--------------+------+-----+---------+-------+

b) From the table CLIENT_MASTER create a new table client1 that contains only
Client_no, Name with all records of CLIENT_MASTER.

create table client1 as (select client_no,cname from client_master);

select*from client1;
+-----------+---------+
| client_no | cname |
+-----------+---------+
| c01001 | ponnu |
| c01002 | mukesh |
| c01003 | siddi |
| c01004 | aswanth |
| c01005 | akash |
| c01006 | sidharth |
| c01007 | manoj |
| c01008 | arjun |
| c01009 | abhijith |
| c01010 | vishnu |
+-----------+---------+

c) From the table CLIENT_MASTER create a new table client2 that has the same
structure as CLIENT_MASTER but with no records

create table client2 as(select*from client_master where 1=2);

select*from client2;
Empty set (0.00 sec)
d) Insert records into table client3 from the CLIENT_MASTER table where the
Client_nois ‘C01001’.

create table client3 as(select* from client_master where client_no='c01001');

select*from client3;
+-----------+-------+------------+-----------+--------+-----------+---------+
| client_no | cname | address | city | pin | state | bal_due |
+-----------+-------+------------+-----------+--------+-----------+---------+
| c01001 | ponnu | pandeshwar | mangalore | 575001 | karnataka | 500.00 |
+-----------+-------+------------+-----------+--------+-----------+---------+

e) For every client in CLIENT_MASTER table increase the Bal_due by 10%.

update client_master set bal_due=bal_due+(0.1+bal_due);

select * from client_master;


+-----------+----------+-------------+------------+--------+------------------+---------+
| client_no | cname | address | city | pin | state | bal_due |
+-----------+----------+-------------+------------+--------+------------------+---------+
| c01001 | ponnu | pandeshwar | mangalore | 575001 | karnataka | 1000.10 |
| c01002 | mukesh | thalangara | ksd | 575002 | kerala | 600.10 |
| c01003 | siddi | baga | bagal | 575067 | goa | 800.10 |
| c01004 | aswanth | dongri | mumbai | 575063 | maharashtra | 1200.10 |
| c01005 | akash | manali | haryana | 575063 | himacahl pradesh | 2000.10 |
| c01006 | sidharth | pumpwell | mangalore | 575002 | karnataka | 1300.10 |
| c01007 | manoj | tirur | malappuram | 671122 | kerala | 1800.10 |
| c01008 | arjun | church road | bangalore | 67567 | karnataka | 3000.10 |
| c01009 | abhijith | koyilandi | calicut | 675784 | kerala | 2400.10 |
| c01010 | vishnu | raman nagar | hyderabad | 675789 | telangana | 4000.10 |
+-----------+----------+-------------+------------+--------+------------------+---------+

f) Update table CLIENT_MASTER change the contents of the field Name to ‘Vijay
Kadam’ and the contents of the field Address to ‘SCT Jay Apmts’ for the record
with Client_no ‘C00002’.

update client_master set cname='vijay kadam',address='sct jay appartment'where


client_no='c01002';

g) Add a new column by name Penalty number (10,2) to table client_master.


alter table client_master add(penalty decimal(10,2));
describe client_master;
+-----------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| client_no | varchar(6) | NO | PRI | NULL | |
| cname | varchar(20) | NO | | NULL | |
| address | varchar(25) | YES | | NULL | |
| city | varchar(20) | YES | | NULL | |
| pin | decimal(6,0) | YES | | NULL | |
| state | varchar(20) | YES | | NULL | |
| bal_due | decimal(7,2) | NO | | NULL | |
| penalty | decimal(10,2) | YES | | NULL | |
+-----------+---------------+------+-----+---------+-------+
h) Change the size of the column Penalty to (8,2) in client_master.
alter table client_master modify penalty decimal(8,2);

describe client_master;
+-----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| client_no | varchar(6) | NO | PRI | NULL | |
| cname | varchar(20) | NO | | NULL | |
| address | varchar(25) | YES | | NULL | |
| city | varchar(20) | YES | | NULL | |
| pin | decimal(6,0) | YES | | NULL | |
| state | varchar(20) | YES | | NULL | |
| bal_due | decimal(7,2) | NO | | NULL | |
| penalty | decimal(8,2) | YES | | NULL | |
+-----------+--------------+------+-----+---------+-------+

i) Change the name of table client_master to client_master1.

rename table client_master to client_master1;

You might also like