Sei sulla pagina 1di 15

14464

EXPERIMENT NO.1 To study basic SQL commands Introduction:


SQL stands for structured query language that enables us to create and operate on relational databases which are sets of related information stored in tables. There are numerous version of SQL. The original version was developed at IBM ,this language originally called sequel, as a part of system R project in the early 1970s .The sequel language has evolved since then and its name has changed to SQL. The SQL has clearly established itself as the standard relational database language. In 1986, the American National Standard Institute (ANSI) published an SQL standard that was updated again in 1992. The most recently version SQL2008 SQL language has several parts: Data definition language: The SQL DDL provides commands for defining relation schemas, deleting relations , creating indexes, modifying relation schemas. Data manipulation language: The SQL DML provides the ability to query information from the database and to insert tuples into deleting tuples from , modify tuples in the database. Integrity:The SQL DDL includes commands for specifying integrity constraints that the data stored in the database must satisfy View definition:The SQL DDL also includes commands for defining views Embedded SQL and dynamic SQL: It defines how SQL statements can be embedded within general purpose programming language such as C,C++ and JAVA By data manipulation ,mean: The insertion of new information into the database The retrieval of information stored in the database The deletion of information from the database

Basic SQL commands: Table creation: create table student( roll_no number(2), reg_no varchar2(2), name varchar2(2)); Retrieve all the data from the table: select * from student

14464

Insert values in a table: insert into student values('a1001',101,'mona'); Table updation Update student set roll_no=101 where city=gurgaon; Delete command Delete from emp Where gross<2200.00;

14464 EXPERIMENT NO.2 To study database creation and table creation statements Introduction:
A database system provides a data definition language to specify the database schema and a data manipulation language to express database queries and updates. A query is a statement requesting the retrieval of information . Table creation: create table student( roll_no number(2), reg_no varchar2(2), name varchar2(2)); Retrieve all the data from the table: select * from student;

Retrieve specific column from the table: select <column name> from student; Retrieve specific row from the table: select * from student where roll_no=101; Insert values in a table: insert into student values('a1001',101,'mona'); create table using primary constraints: create table student( reg_no varchar2(7)PRIMARY KEY, name varchar2(9)NOT NULL); Retrieve specific row and specific column: Select name from student

14464
where branch=it; To view column and its definition: exec SP_ column from <table name>; Rename table name: exec SP_renamestudent,student1; View records by given character: select * from student where city likea%; Ascending order: select * from student orderby name; Descending order: select * from student orderby name desc; See the record of top of table: Select top15 from student; To see all the tables in the database: select * from sys.table Print name between a and r select * from student where name between a and r; Table updation Update student set roll_no=101 where city=gurgaon;

14464

EXPERIMENT NO.3 To implement the operations on the table Introduction:


A table is a database object that holds the user data. The simplest analogy is to think of a table as a spreadsheet. The cell of the spreadsheet equate to the column of the table having a specific datatype associated with them.

create table client_master( clientno varchar2(10) primary key, name varchar2(20), city varchar(20),pincode number(6),state varchar2(15),baldue number(10,2)); insert into client_master values('c006','shiv ,'manglore',560050,karnataka,0); select * from client_master; create table product_master( productno varchar2(6) primary key,description varchar2(15),profit number(4,2),unit_measure varchar2(6),quantity_on_hand number(6),reorder_level number(8),sell_price number(6),cost_price number(8)); insert into product_master values('p005','suit ',5 ,'Rs',400,40,800,400); select * from product_master; create table salesman_master( salesmanno varchar2(6),salesmanname varchar2(6),address varchar2(20),city varchar2(10),pincode number(6),state varchar(10),salary number(10),target_to_get number(10),yesterday_sale number(6,2),remark varchar2(10)); insert into salesman_master values('s005','hari','B.9','mumbai',400001,'maharastra',3000,100,50,'good'); select * from salesman_master; select name from client_master; select * from client_master; select name,city,state from client_master; select * from client_master where city='mumbai'; select * from salesman_master where salary=30000;

14464

update client_master set city='bangalore' where clientno='c005'; update client_master set balancedue=1000 where clientno='c001'; update product_master set cost_price=950 where description=trouser; update salesman_master set city='pune' where pincode=400042; delete from salesman_master where saleamt=3500; delete from client_master where state='Tamil Nadu';

alter table client_master add telephoneno number(10);

14464 EXPERIMENT NO.4 To implement constraints on the table


create table student( reg_no varchar2(7)PRIMARY KEY, name varchar2(9)NOT NULL, city varchar2(10), roll_no number(5)unique, branch varchar2(3), CHECK(roll_no<14459)); insert into student values('a1001','mona',gurgaon,14447,IT); insert into student values('a001','mahi',gurgaon,14444,IT); insert into student values('a1003','sonia','delhi',14455,IT); select * from student; create table result( reg_no varchar2(7)references student, total_marks number(7), percentage number(2)); insert into result values(a1001,500,80); select* from result; insert into result values(a1003,550,85);

14464 EXPERIMENT NO.5 To implement the concept of joins


create table customer( id varchar2(20)PRIMARY KEY, name varchar2(10), age number(2), address varchar2(50), salary number(5)); insert into customer values('c@gmail.com','monika',20,'gurgaon',55000); select * from customer

create table orders( order_id varchar2(6)PRIMARY KEY, odate date, id varchar2(20)references customer, amount number(6));

insert into orders values('o003','28 feb 2013','c@gmail.com',4000); select * from orders select name,amount,salary from customer inner join orders on customer.id=orders.order_id; select name from customer right join orders on customer.id=orders.order_id; select salary from customer left join order on customer.id=order.id; select name,amount,order_id from customer full join order on customer.id=order.id; select * from customer

14464

14464

EXPERIMENT NO.6 To implement the aggregate functions


create table customer( id varchar2(20)PRIMARY KEY, name varchar2(10), age number(2), address varchar2(50), salary number(5)); insert into customer values('c@gmail.com','monika',20,'gurgaon',55000); select * from customer select salary maximum from customer; select * from dual select 2*2 from dual select sysdate from dual select upper(name)from customer select sysdate "mydate" from dual select months_between('13 march 2013','13 may 2013')from dual select to_char(sysdate,'dd mm yy')from dual select sqrt(4) from dual select exp(5) from dual select power(2,4) from dual select absolute(-15) from dual select round(15.19,1) from dual select least( 1,2,3 ),least(1,2,3)from dual select ceil(fan)from dual select ascii('z') ,ascii('x') from dual

14464 EXPERIMENT NO.7 To implement the concept of grouping the data


create table student2( roll_no number(2), reg_no varchar2(2), name varchar2(20), branch varchar2(5), sdate date, PRIMARY KEY(roll_no)); insert into student2 values(3,'03','monika','cse','12 march 2013'); select * from student2 create table results3( sroll_no number(2) references student2, result varchar2(6), sbranch varchar2(5) );

select avg(roll_no) from student2 group by branch; select branch,count(roll_no) from student2 group by branch; select branch,count(roll_no) from student2; select * from student2 where sdate < '12 march 2013';

14464

EXPERIMENT NO.8 To implement the concept of Sub Queries


create table student( roll_no number(2), reg_no varchar2(2), name varchar2(20), branch varchar2(5), sdate date, PRIMARY KEY(roll_no)); insert into student values(3,'03','monika','it','12 march 2013'); select * from student create table results5( sroll_no number(2) references student, result varchar2(6), sbranch varchar2(5) ); select avg(roll_no) from student group by branch select branch,roll_no, result from student,results5 select name,roll_no from student,results5 where student.branch=results5.sbranch;

14464

14464 EXPERIMENT NO.9 To implement the concept of views


create table student( roll_no number(2), reg_no varchar2(2), name varchar2(20), branch varchar2(5), sdate date, PRIMARY KEY(roll_no)); insert into student values(3,'03','monika','it','12 march 2013'); select * from student create table results5( sroll_no number(2) references student, result varchar2(6), sbranch varchar2(5) ); create table emp( name varchar2(19) as select name varchar2(19) from student); create view employ as select student.name, results5.sbranch from student, results5; select*from employ; drop view employ;

14464 EXPERIMENT NO.10 To implement the concept of Indexes


SYNTAX: create index<index name> on tablename(<column name>,<column name>); EXAMPLE: create index empl1 on student(roll_no,branch); SYNTAX: Drop index <index name> EXAMPLE: drop index emp1;

Potrebbero piacerti anche