SQL 2
SQL 2
Lab
Bennett University
CREATE DATABASE - creates a new database
CREATE
•CREATE DATABASE databasename;
List of
CREATE TABLE - creates a new table
CREATE
•CREATE TABLE table_name ( column1 datatype,....);
queries
ALTER TABLE - modifies a table
ALTER
•ALTER TABLE table_name ADD column_name datatype;
Orders table
• INSERT INTO orders (oid, orderdate,amount,cid)
values ('1','2020-04-04','100','1');
• INSERT INTO orders (oid, orderdate,amount,cid)
values ('2','2020-05-05','200','2');
• INSERT INTO orders (oid, orderdate,amount,cid)
values ('3','2020-06-06','300','1');
• INSERT INTO orders (oid, orderdate,amount,cid)
values ('4','2020-07-07','400','3');
• INSERT INTO orders (oid, orderdate,amount,cid)
values ('5','2020-08-08','500','4');
output
Select Distinct records from table
• select DISTINCT cid from orders;
output
Delete Particular records from table
• delete from orders where amount <=200;
• select * from orders;
oid orderdate amount cid
output
Update Particular records in table
• update orders set amount=800 where oid=1;
• select * from orders;
oid orderdate amount cid
output
condition
• select oid, orderdate, amount, cid from orders
where oid>2 AND amount<500;
oid orderdate amount cid
output
• AND
• OR
• NOT equal to ( <> )
SORTING
• select *from orders ORDER BY amount;
output
output
LIMIT 10 would return the first 10 rows
matching the SELECT criteria.
OFFSET
• select *from orders ORDER BY amount LIMIT 5
OFFSET 3;
oid orderdate amount cid
output
select SQRT(16);
INSERT INTO orders (cid, cust_name, oid, amount) values (1, 'abc', 1231, 500);
INSERT INTO orders (cid, cust_name, oid, amount) values (1, 'abc', 1232, 500);
INSERT INTO orders (cid, cust_name, oid, amount) values (2, 'def', 1233, 500);
INSERT INTO orders (cid, cust_name, oid, amount) values (3, 'ghi', 1234, 500);
create table B(
three varchar(5),
four varchar(5));
No Duplicate
Rows
Orders table
create table orders(
oid int(10),
orderdate date,
amount varchar(20),
cid int(10));