DBMS Lab File-1
DBMS Lab File-1
Objective:-
Create tables and specify the Questionnaires in SQL.
Creating a table-
Syntax-
Create table tablename
(columnname datatype(size), columnname datatype(size));
Syntax-
CREATE TABLE TABLENAME
[(columnname, columnname, ………)]
AS SELECT columnname, columnname ......... FROM tablename;
OUTPUT:-
1
Practical #02
Objective:
Performing insertion, deletion, modification, altering and updating operations on the records
based on conditions.
2
Selecting a data set from table data-
Syntax-
SELECT columnname, columnname FROM tablename WHERE searchcondition;
OUTPUT:-
3
Practical #03
Objective:
To Manipulate the Operations on the table.
Deletion Operation:-
A delete query is expressed in much the same way as Query. We can delete whole tuple
(rows) we can delete values on only particulars attributes.
Deletion of all rows
Syntax:
Delete from tablename :
Deletion of specified number of rows:
+ Addition - Subtraction
* multiplication ** exponentiation
/ Division () Enclosed operation
Syntax:
Select column name
result_columnname, Columnname
result_columnname, From table name;
Oracle functions:
Syntax:
Avg ([distinct/all]n)
Min return minimum value of expr.
Syntax:
MIN((distinct/all )expr)
Count Returns the no of rows where expr is not null
4
Syntax:
Count ([distinct/all)expr]
Count (*) Returns the no rows in the table, including duplicates and those with nulls.
Max Return max value of expression.
Syntax:
Syntax:
Sum ([distinct/all]n)
Sorting of data in table
Syntax:
Select columnname,
columnname From
table
Order by columnname;
OUTPUT:-
5
Practical #04
Objective:-
To Implement the structure of the table Modifying the Structure of Tables.
Syntax:
ALTER TABLE tablename
ADD (newcolumnname newdatatype (size));
Syntax:
ALTER TABLE tablename:
MODIFY (newcolumnname newdatatype (size));
Removing/Deleting Tables
Following command is used for removing or deleting a table.
Syntax:
DROP TABLE tablename:
Syntax:
ALTER TABLE tablename
ADD PRIMARY KEY (columnname);
6
DROP the PRIMARY KEY-
Syntax:
ALTER TABLE tablename DROP PRIMARY KEY
OUTPUT:-
7
Practical #05
Objective:-
To Implement the restrictions on the table.
Syntax:
Create table tablename
(columnname data type (size) not null ……)
Primary Key:
Syntax:
primary key as a column constraint Create table tablename
(columnname datatype (size) primary key,….)
Primary key as a table constraint
Create table tablename
(columnname datatype (size), columnname datatype(
size)… Primary key (columnname,columnname));
Syntax:
Create table tablename
(columnname datatype (size) default value,….);
Syntax :
Create table table name
(columnname datatype (size) references another table name);
Syntax :
Create table name
(columnname datatype
(size)…. primary key (columnname);
foreign key (columnname)references table name);
8
Check Integrity Constraints:
Syntax:
Create table tablename
(columnname datatype (size) CONSTRAINT
constraintname) Check (expression) );
OUTPUT:-
9
Practical #06
Objective:-
To implement the concept of Joins
1.Cartesian product:-
Consider two table student and course Select B.*,P.* FROM student B, course P;
2.INNER JOIN:-
Cartesian product followed by selection Select B.*,P.* FROM student B, Course P WHERE
B.course # P.course # ;
OUTPUT:-
10
Practical #07
Syntax:
SELECT columnname, columnname FROM tablename
GROUP BY columnname;
At times it is useful to state a condition that applies to groups rather than to tuples.
For example, we might be interested in only those branches where the average account
balance is more than 1200. This condition does not apply to a single tuple, rather it applies
to each group constructed by the GROUP BY clause. To express such Questionary, we use
the having clause of SQL. SQL applies predicates in the having may be used.
Syntax:
SELECT columnname, columnname
FROM tablename
GROUP BY columnname; HAVING searchcondition;
OUTPUT:-
11
Practical #08
SubQueries:-
Example: -
Creating clientmaster table from oldclient_master, table Create table client_master
AS SELECT * FROM oldclient_master;
Output:
Records only in Query one + records only in Query two + A single set of records with is
common in the both Queries.
Syntax:
SELECT columnname, columname FROM tablename 1
UNION
SELECT columnname, columnname From tablename2;
Intersect Clause:
Output =A single set of records which are common in both Queries Syntax:
SELECT columnname, columnname FROM tablename 1
INTERSECT
SELECT columnname, columnname FROM tablename
2;
MINUS CLAUSE:-
SELECT columnname, columnname FROM tablename ;
MINUS
SELECT columnname, columnname FROM tablename ;
OUTPUT:-
12
Practical #09
Objective:-
To implement the concept of Indexes and views.
Syntax:
(Simple)
CREATE INDEX index_name ON tablename(colu mn name);
Composite Index:-
CREATE INDEX index_name
ON tablename(columnname,columnname);
Creating an UniQuestion Index:-
CREATE UNIQUESTION INDEX
indexfilename ON tablename(columnname);
Creation of Views:-
Syntax:-
CREATE VIEW viewname AS SELECT columnname,columnname FROM tablename
WHERE columnname=expression_list;
OUTPUT:-
13
Practical # 10
Objective:-
To implement the basics of PL/SQL.
Example:
Syntax:
IF <condition> THEN
<Action> ELSEIF<condition>
<Action> ELSE
<Action> ENDIF;
14
OUTPUT:-
19 21 8 b is maximum 21
15