0% found this document useful (0 votes)
351 views26 pages

Phpmyadmin: Mysql

The document describes four experiments related to SQL and database design. Experiment 1 involves creating SQL tables for a client and product database and inserting sample data. Experiment 2 displays SQL queries using the SELECT statement with a WHERE clause to filter results. Experiment 3 covers SQL commands like UPDATE, ALTER, RENAME, DELETE, and DROP. Experiment 4 implements data constraints at the column and table level when creating tables.

Uploaded by

Nishant Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
351 views26 pages

Phpmyadmin: Mysql

The document describes four experiments related to SQL and database design. Experiment 1 involves creating SQL tables for a client and product database and inserting sample data. Experiment 2 displays SQL queries using the SELECT statement with a WHERE clause to filter results. Experiment 3 covers SQL commands like UPDATE, ALTER, RENAME, DELETE, and DROP. Experiment 4 implements data constraints at the column and table level when creating tables.

Uploaded by

Nishant Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

EXPERIMENT 1

Objective: Introduction to SQL. Also design SQL tables for Client & Product database and
display all the values.

Software Used: phpMyAdmin(MySQL)

Procedure: SQL stands for Structured Query Language and is a widely used database language,
providing means of data manipulation (store, retrieve, update, delete) and database creation.
Almost all modernRelational Database Management Systems like MS SQL Server, Microsoft
Access, MSDE, Oracle, DB2, Sybase, MySQL, Postgres and Informix use SQL as standard
database language. The foundation of every Relational Database Management System is a
database object called table. Every database consists of one or more tables, which store the
database’s data/information. Each table has its own unique name and consists of columns and
rows. Here is an example of a SQL query having different commands.

Q1. Create the following tables:


i) Client_master

columnname datatype size


client_no varchar2 6
name varchar2 20
address1 varchar2 30
address2 varchar2 30
city varchar2 15
state varchar2 15
pincode number 6
bal_due number 10,2

ii) Product_master
Columnname datatype size
Product_no varchar2 -
Description varchar2 -
Profit_percent number -
Unit_measure varchar2 -
Qty_on_hand number -
Reoder_lvl number -
Sell_price number -
Cost_price number -
QUARY:

CREATE TABLE Client_master_093( client_no varchar(6), name varchar(20), adderss1 varchar(30),


adderss2 varchar(30), city varchar(15), state varchar(15), pincode int(6), bal_due float(10,2))

QUARY:
Create table product_master_093 (Product_no varchar(25), Description varchar(25),
Profit_percent float(2,2), Unit_measure varchar(25), Qty_on_hand int(10), Reoder_lvl int(10),
Sell_price int(10), Cost_price int(10));
Q2- Insert the following data into their respective tables:

Client_no Name city pincode state bal.due

0001 Ivan Bombay 400054 Maharashtra 15000


0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000
0006 Rukmini Bombay 400050 Maharashtra 0

QUARY:
Insert into client_master_093 (Client_no,Name,city,pincode,state,bal_due)
values('0001','Ivan','Bombay',400054,'Maharashtra',15000);

QUARY:
SELECT*FROM ‘client_master_093’
Data for Product Master:
Product No. Desciption Profit % Unit Qty Reorder Sell Cost
Percent measured on hand lvl price price

P00001 1.44floppies 5 piece 100 20 525 500


P03453 Monitors 6 piece 10 3 12000 11200
P06734 Mouse 5 piece 20 5 1050 500
P07865 1.22 floppies 5 piece 100 20 525 500
P07868 Keyboards 2 piece 10 3 3150 3050
P07885 CD Drive 2.5 piece 10 3 5250 5100
P07965 540 HDD 4 piece 10 3 8400 8000
P07975 1.44 Drive 5 piece 10 3 1050 1000
P08865 1.22 Drive 5 piece 2 3 1050 1000

QUARY:
insertintoproduct_master_093 (‘Product_no’, ‘Description’, ‘Profit_percent’, ‘Unit_measure’,
‘Qty_on_hand’, ‘Reoder_lvl’, ‘Sell_price’, ‘Cost_price’) values ('P00001', '1.44floppies', 5,
'piece',100,20,525,500)
QUARY:
SELECT*FROM ‘product_master_093’
EXPERIMENT 2

Objective: Display the SQL Queries for command Select with Where clause.

Software Used: phpMyAdmin(MySQL)

Procedure: SQL stands for Structured Query Language and is a widely used database language,
providing means of data manipulation (store, retrieve, update, delete) and database creation.
Almost all modernRelational Database Management Systems like MS SQL Server, Microsoft
Access, MSDE, Oracle, DB2, Sybase, MySQL, Postgres and Informix use SQL as standard
database language. The foundation of every Relational Database Management System is a
database object called table. Every database consists of one or more tables, which store the
database’s data/information. Each table has its own unique name and consists of columns and
rows.Here is an example of a SQL query having different commands.

Q3:- On the basis of above two tables answer the following Questionnaires:

i. Find out the names of all the clients.


QUARY:
SELECT name FROM ‘client_master_093’
ii. Retrieve the list of names and cities of all the clients.

QUARY:
SELECT name,city FROM ‘client_master_093’

iii. List the various products available from the product_master table.

QUARY:
SELECT DISTINCT Product_no,Description FROM ‘product_master_093’
iv. List all the clients who are located in Bombay.

QUARY:
SELECT *FROM ‘client_master_093’ WHERE city= ‘Bombay’

v. Display the information for client no 0001 and 0002.

QUARY:
SELECT *FROM ‘client_master_093’ WHERE client_no= ‘0001’ OR client_no= ‘0002’
vi. Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.

QUARY:
SELECT*FROM ‘product_master_093’ WHERE Description= ‘1.44 Drive’ OR Description=
‘1.22 Drive’

vii.Find all the products whose sell price is greater than 5000.

QUARY:

SELECT*FROM ‘product_master_093’ WHERE Sell_price>5000


viii. Find the list of all clients who stay in city ‘Bombay’ or city ‘Delhi’ or ‘Madras’.

QUARY:
SELECT *FROM ‘client_master_093’ WHERE city= (‘Bombay’ OR ‘Delhi’ OR ‘Madras’)

ix. Find the product whose selling price is greater than 2000 and less than or equal to
5000.

QUARY:
SELECT*FROM ‘product_master_093’ WHERE Sell_price>2000 OR Sell_price<5000
x. List the name, city and state of clients not in the state of ‘Maharashtra’.

QUARY:
SELECT *FROM ‘client_master_093’ WHERE NOT state= ‘Maharashtra’
Experiment No. 3

Objective :Create the SQL queries for commands like update, alter, rename, delete and drop.

Software Used: phpMyAdmin(MySQL)

Question.1 Using the table client master and product master answer the following
Questionnaires-

i. Change the selling price of ‘1.44 floppy drive to Rs.1150.00

QUARY:
UPDATE product_master_093 SET Sell_price=11500.00 WHERE Description= ‘1.44floppies’

QUARY:
SELECT*FROM product_master_093
ii. Delete the record with client 0001 from the client master table.

QUARY:
DELETE FROM ‘client_master_093’ WHERE client_no=0001

QUARY:
SELECT *FROM ‘client_master_093’
iii. Change the city of client_no’0005’ to Bombay.

QUARY:
UPDATE ‘client_master_093’ SET city= ‘Bombay’ WHERE client_no=0001

QUARY:
SELECT *FROM ‘client_master_093’
iv. Change the bal_due of client_no ‘0002, to 1000.

QUARY:
UPDATE client_master_093 SET bal_due=1000 WHERE client_no=0002

QUARY:
SELECT*FROM ‘client_master_093’
v. Find the products whose selling price is more than 1500 and also find the new selling
price as original selling price *15.

QUARY:
SELECT Description,Sell_price*15 FROM ‘product_master_093’ WHERE Sell_price>1500
Experiment 4

Objective: - To Implement the restrictions on the table.


Data constraints: Besides the cell name, cell length and cell data type there are other parameters
i.e. other data constrains that can be passed to the DBA at check creation time. The constraints
can either be placed at column level or at the table level.

i. Column Level Constraints: If the constraints are defined along with the column
definition, it is called a column level constraint.
ii. Table Level Constraints: If the data constraint attached to a specify cell in a table
reference the contents of another cell in the table then the user will have to use table level
constraints.
Null Value Concepts:- while creating tables if a row locks a data value for particular column
that value is said to be null . Column of any data types may contain null values unless the column
was defined as not null when the table was created
Question.1 Create the following tables:
1. Sales_master

Columnname Datatype Size Attributes


Salesman_no varchar2 6 Primary key/first letter
must start with ‘s’
Sal_name varchar2 20 Not null
Address varchar2 Not null
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8 Not null, cannot be 0
Tgt_to_get Number 6 Not null, cannot be 0
Ytd_sales Number 6 Not null, cannot be 0
Remarks Varchar2 30

QUERY:

create table sales_master_093(


Salesman_no varchar(6) primary key CHECK (Salesman_no LIKE 's'),
Sal_name varchar(20) NOT NULL,
Address varchar(20) NOT NULL,
City varchar(20), State varchar(20), Pincode int(6),
Sal_amt int(8) NOT NULL check(Sal_amt != 0),
Tgt_to_get int(6) NOT NULL check(Tgt_to_get != 0),
Ytd_sales int(6) NOT NULL check(Ytd_sales != 0),
Remarks varchar(30));
OUTPUT:

QUERY:

desc sales_master_093;

OUTPUT:

2. Sales_order

Columnname Datatype Size Attributes


S_order_no varchar2 6 Primary/first letter must be 0
S_order_date smallDatetime 6

Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6 Foreign key references
salesman_no of
salesman_master table
Dely_type Char 1 Delivery
part(p)/full(f),default f
Billed_yn Char 1
Dely_date smallDatetime
Order_status Varchar2 10 Values (‘in
process’;’fulfilled’;back
order’;’canceled
QUERY:
create table sales_order_093(
S_order_no varchar(6) PRIMARY KEY CHECK(s_order_no LIKE '0%'),
S_order_date DATE, Client_no varchar(25), Dely_add varchar(6),
Salesman_no varchar(6) REFERENCES sale_master(sales_no),
Dely_type varchar(1) CHECK(dely_type IN('p','f')) DEFAULT 'f',
billed_yn varchar(1), dely_date DATE,
order_status varchar(10) CHECK(order_status IN('in process','back order','cancelled'))
);

OUTPUT:

QUERY:

desc table sales_order_093;

OUTPUT:

3. Sales_order_details

Column Datatype Size Attributes

S_order_no Varchar2 6 Primary key/foreign


key references
s_order_no of
sales_order
Product_no Varchar2 6 Primary key
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2
QUERY:

create table sales_order_details_093


(
s_order_no varchar(6) PRIMARY KEY REFERENCES sales_order(s_order_no),
product_no varchar(6) REFERENCES products(product_no),
qty_ordered int(8),
qty_disp int(8),
product_rate decimal(10, 2)
);

OUTPUT:

QUERY:

desc table sales_order_details_093;

OUTPUT:
Experiment 5

Objective :- To Implement the structure of the table

Theory: -
Modifying the Structure of Tables- Alter table command is used to changing the structure of a table.
Using the alter table clause you cannot perform the following tasks:

i. change the name of table


ii. change the name of column
iii. drop a column
iv. decrease the size of a table if table data exists.

The following tasks you can perform through alter table command.

Adding new columns:

Syntax :
ALTER TABLE tablename
ADD (newcolumnname newdatatype (size));
Modifying existing table

Syntax:
ALTER TABLE tablename
MODIFY (newcolumnname newdatatype (size));

Removing/Deleting Tables- Following command is used for removing or deleting a table.

Syntax:
DROP TABLE tabename:
Defining Integrity constraints in the ALTER TABLE command-
You can also define integrity constraints using the constraint clause in the ALTER TABLE command. The
following examples show the definitions of several integrity constraints.

Add PRIMARY KEY-


Syntax:
ALTER TABLE tablename
ADD PRIMARY KEY(columnname);

Add FOREIGN KEY-


Syntax:
ALTER TABLE tablename
ADD CONSTRAINT constraintname FOREIGN KEY(columnname) REFERENCES tablename;
Droping integrity constraints in the ALTER TABLE command:

You can drop integrity constraint if the rule that if enforces is no longer true or if the constraint is no
longer needed. Drop the constraint using the ALTER TABLE command with the DROP clause. The
following examples illustrate the droping of integrity constraints.
DROP the PRIMARY KEY-
Syntax:
ALTER TABLE tablename
DROP PRIMARY KEY

DROP FOREIGN KEY-


Syntax:
ALTER TABLE tablename DROP CONSTRAINT constraintname;

Question 1. Create the following tables:

Challan_Header
Column name data type size Attributes
Challan_no varchar2 6 Primary key
s_order_no varchar2 6 Foreign key references s_order_no of
sales_order table
challan_date date not null
billed_yn char 1 values (‘Y’,’N’). Default ‘N’

Query:

create table challan_header_093


(
challan_no varchar(6) PRIMARY KEY,
s_order_no varchar(12) REFERENCES sales_order(s_order_no),
challan_date DATE,
billed_yn char(1) CHECK(billed_yn IN('Y','N')) DEFAULT 'N'
);

Output:

Query:

desc challan_header_093;
Output:

Table Name: Challan_Details

Column name data type size Attributes


challan_no varchar2 6 Primary key
product_no varchar2 6 Primary key/Foreign key references
product_no of product_master
qty_disp number 4, 2 not null

Query:

create table challan_details_093


(
challan_no varchar(6) PRIMARY KEY,
product_no varchar(6) REFERENCES product_master(product_no),
qty_disp decimal(4,2) NOT NULL check(qty_disp != 0)
);

Output:

Query:

desc challan_details_093;
Output:

Q2. Insert the following values into the challan header and challan_details tables:

(i) Challan No S_order No Challan Date Billed

CH900 1019001 12-DEC-95 Y


CH865 046865 12-NOV-95 Y
CH396 5010008 12-OCT-95 Y
Query:

insert into challan_header_093


values row('CH900', '1019001', '95-12-12', 'Y'),
row('CH865', '046865', '95-11-12', 'Y'),
row('CH396', '5010008', '95-10-12', 'Y');

Output:

Query:
select * from challan_header_093;

Output:
Q3. Make the primary key to client_no in client_master.

Query:
alter table client_master_093 add PRIMARY KEY(client_no);

Output:

Query:
desc client_master_093;

Output:

Q4. Add a new column phone_no in the client_master table.

Query:
alter table client_master_093 add phone_no int(11);

Output:

Query:
show COLUMNS from client_master_093 like ‘ph%’;

Output:
Q5. Add the not null constraint in the product_master table with the columns description, profit
percent, and sell price and cost price.

Query:
alter table product_master_093 modify COLUMN Description varchar(25) NOT NULL;
alter table product_master_093 modify COLUMN Profit_percent int NOT NULL;
alter table product_master_093 modify COLUMN Sell_price int NOT NULL;
alter table product_master_093 modify COLUMN Cost_price int NOT NULL;

Output:

Query:
desc product_master_093;

Output:

Q6. Select product_no, description where profit percent is between 20 and 30 both inclusive.

Query:
select Product_no, Description from product_master_093 where Profit_percent between 20
and 30;

Output:

You might also like