Phpmyadmin: Mysql
Phpmyadmin: Mysql
Objective: Introduction to SQL. Also design SQL tables for Client & Product database and
display all the values.
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.
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:
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:
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
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.
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:
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’
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:
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.
Question.1 Using the table client master and product master answer the following
Questionnaires-
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
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
QUERY:
QUERY:
desc sales_master_093;
OUTPUT:
2. Sales_order
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:
OUTPUT:
3. Sales_order_details
OUTPUT:
QUERY:
OUTPUT:
Experiment 5
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:
The following tasks you can perform through alter table command.
Syntax :
ALTER TABLE tablename
ADD (newcolumnname newdatatype (size));
Modifying existing table
Syntax:
ALTER TABLE tablename
MODIFY (newcolumnname newdatatype (size));
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.
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
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:
Output:
Query:
desc challan_header_093;
Output:
Query:
Output:
Query:
desc challan_details_093;
Output:
Q2. Insert the following values into the challan header and challan_details tables:
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:
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: