RECORD_RDBMS 10
RECORD_RDBMS 10
RDBMS LABORATORY
(HBCA21AL2)
2023 -2024
STUDENT NAME :
REGISTER NUMBER:
DEPARTMENT OF COMPUTER APPLICATIONS
BONAFIDE CERTIFICATE
of 2023-2024.
SQL BASICS:
1.DDL-
1. CREATE,ALTER,DROP
2.DML-
INSERT, UPDATE, DELETE
3.DRL-
SELECT & ITS OPERATORS
2. VIEWS
INTEGRITY CONSTRAINTS-
3. NAMING CONSTRAINTS
SUB QUERIES :
4. A. NESTED QUERIES
B.COMPLEX QUERIES
Aim:
Procedure:
DDL COMMANDS
2. DROP : DROP command is used to delete the object from the database.
CREATING TABLE:
Syntax
CREATE TABLE EMP (EMPNO NUMBER (4), ENAME VARCHAR2 (10), DESIGNATION
VARCHAR2 (10), SALARY NUMBER (8,2))
Table created.
DESCRIBE TABLE:
Syntax:
2) Write a query to display the column name and data type of the table employee.
DESC EMP
Table Column Data Length Precision Scale Primary Nullable Default Comment
Type Key
EMP EMPNO Number - 4 0 - - -
ENAME Varchar2 10 - - - - -
DESIGNATION Varchar2 10 - - - - -
SALARY Number - 8 2 - - -
1-4
CREATE NEW TABLE FROM AN EXISTING TABLE WITH ALL FIELDS:
Syntax:
CREATE TABLE <TRAGET TABLE NAME> SELECT * FROM <SOURCE TABLE NAME>
3) Write a query for create EMP1 table from an existing table EMP with all the fields
Table created.
DESC EMP1
Table Column Data Length Precision Scale Primary Nullable Default Comment
Type Key
EMP1 EMPNO Number - 4 0 - - -
ENAME Varchar2 10 - - - - -
DESIGNATION Varchar2 10 - - - - -
SALARY Number - 8 2 - - -
1-4
Syntax
4) Write a query for create a from an existing table with selected fields
Table created.
DESC EMP2
Table Column Data Type Length Precision Scale Primary Key Nullable Default Comment
EMP2 EMPNO Number - 4 0 - - -
ENAME Varchar2 10 - - - - -
1-2
ALTER SINGLE COLUMN
Syntax :
5) Write a Query to Alter the column EMPNO NUMBER (4) TO EMPNO NUMBER
Table altered.
DESC EMP
Table Column Data Length Precision Scale Primary Nullable Default Comment
Type Key
EMP EMPNO Number - 6 0 - - -
ENAME Varchar2 10 - - - - -
DESIGNATION Varchar2 10 - - - - -
SALARY Number - 8 2 - - -
1-4
ALTER TABLE WITH MULTIPLE COLUMN:
Syntax:
6) Write a Query to alter the table emp with multiple columns (EMPNO, ENAME)
Table altered.
DESC EMP
Table Column Data Length Precision Scale Primary Nullable Default Comment
Type Key
EMP EMPNO Number - 7 0 - - -
ENAME Varchar2 12 - - - - -
DESIGNATION Varchar2 10 - - - - -
SALARY Number - 8 2 - - -
1-4
ADD NEW COLUMN
Syntax :
ALTER TABLE <TABLE NAME> ADD (<COLUMN NAME> <DATA TYPE> <SIZE>
7) Write a query to add a new column into emp Table
Table altered.
DESC EMP
Tabl Column Data Lengt Precisio Scal Primar Nullabl Defaul Commen
e Type h n e y Key e t t
EMP EMPNO Number - 7 0 - - -
ENAME Varchar 12 - - - - -
2
DESIGNATION Varchar 10 - - - - -
2
SALARY Number - 8 2 - - -
QUALIFICATIO Varchar 6 - - - - -
N 2
1-5
ADD MULTIPLE COLUMNS INTO TABLE
Syntax
Table altered.
DESC EMP
Tabl Column Data Lengt Precisio Scal Primar Nullabl Defaul Commen
e Type h n e y Key e t t
EMP EMPNO Number - 7 0 - - -
ENAME Varchar 12 - - - - -
2
DESIGNATION Varchar 10 - - - - -
2
SALARY Number - 8 2 - - -
QUALIFICATIO Varchar 6 - - - - -
N 2
DOB Date 7 - - - - -
DOJ Date 7 - - - - -
1-7
REMOVE / DROP
Syntax
Table altered.
DESC EMP
Tabl Column Data Lengt Precisio Scal Primar Nullabl Defaul Commen
e Type h n e y Key e t t
EMP EMPNO Number - 7 0 - - -
ENAME Varchar 12 - - - - -
2
DESIGNATION Varchar 10 - - - - -
2
SALARY Number - 8 2 - - -
QUALIFICATIO Varchar 6 - - - - -
N 2
DOB Date 7 - - - - -
1-6
DROP MULTIPLE COLUMNS
Syntax
Table altered.
DESC EMP
Table Column Data Length Precision Scale Primary Nullable Default Comment
Type Key
EMP EMPNO Number - 7 0 - - -
ENAME Varchar2 12 - - - - -
DESIGNATION Varchar2 10 - - - - -
SALARY Number - 8 2 - - -
1-4
Result:
EX.NO: 1 .2 SQL BASICS 2.IMPLEMENTATION ON DML IN RDBMS
DATE:
Aim:
Procedure:
DML COMMANDS
Syntax
1 row created.
Syntax :
<COLUMN NAME>=<VALUE>
2) Write a query to update salary is 16000 in emp table where empno is 101
1 row updated.
Syntax:
<COLUMN NAME>=<VALUE>;
EMPNO=101;
1 row updated.
Syntax :
1 row deleted.
NO DATA FOUND
Result:
EX.NO: 1 .3 SQL BASICS
DATE: 3. DRL DATA RETRIEVAL IMPLEMENTING ON SELECT
COMMANDS
Aim:
Procedure:
EMP Table having the following records:
SELECT STATEMENT
The SELECT statement is used to select data from a database. The data returned is stored in a
result table, called the result-set.
Syntax
1) Write a query to Fetch EMPNO, EName and Salary fields of the customers available in
EMP table.
Syntax:
SELECT column1, column2, column FROM table_name WHERE [condition]
3) Write a query to fetch EMPNO, ENAME, And Salary fields from the EMP table where
salary is greater than 20000
SELECT EMPNO, ENAME, SALARY FROM EMP WHERE SALARY > 20000
4) Write a query to fetch empno, eName and Salary fields from the emp table for an
employee with name KALA.
The AND operator allows the existence of multiple conditions in an SQL statement's WHERE
clause.
Syntax:
SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND
[condition2]...AND [conditionN];
5) Write a query to fetch empno, eName and Salary fields from the emp table where
salary is greater than 20000 AND designation=’PROF’
The OR operator is used to combine multiple conditions in an SQL statement's WHERE clause.
Syntax:
SELECT column1, column2, columnN FROM table_name WHERE [condition1] OR
[condition2]...OR [conditionN]
6) Write a query to fetch empno, eName ,desination, Salary fields from the emp table
where salary is greater than 20000 or designation=’PROF’
The SQL LIKE clause is used to compare a value to similar values using wildcard operators.
There are two wildcards used in conjunction with the LIKE operator:
The percent sign represents zero, one, or multiple characters. The underscore represents a single
number or character. The symbols can be used in combinations.
Syntax:
7) Write a query to display all the records from emp table where SALARY starts with
5
The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on
one or more columns.
Aim:
Procedure:
SQL COMMANDS
COMMAND DESCRIPTION: INSERT command is used to insert a new row into the view.
COMMAND DESCRIPTION: DELETE command is used to delete a row from the view.
COMMANDS EXECUTION
CREATION OF TABLE
Table created.
TABLE DESCRIPTION
DESC EMP77
Table Column Data Type Length Precision Scale Primary Key Nullable Default Comment
VIEW CREATED.
DESCRIPTION OF VIEW
2) DESC EMPVIEW
Data Primary
Table Column Length Precision Scale Nullable Default Comment
Type Key
EMPVIEWENAME Varchar2 10 - - - - -
EMPNO Number - 8 0 - - -
DEPTNAME Varchar2 10 - - - - -
DEPTNO Number - 5 0 - - -
DOJ Date 7 - - - - -
1 ROW INSERTED
1 ROW DELETED.
UPDATE STATEMENT:
1 row(s) updated.
DROP A VIEW:
VIEW DROPED
STATEMENT:
Type 1
12) CREATE OR REPLACE VIEW EMPview3(EID,NAME,date_of_joining) AS SELECT
EMPNO,ENAME,doj FROM EMP77
View created.
TYPE 2
Aim:
Procedure:
I) Primary key Constraint
1 row(s) inserted.
insert into employee10 values(101,'dhanu', 'clerk',1000,1)
ORA-00001: unique constraint (SYSTEM.SYS_C004101) violated
2. Write a query to create primary constraints in column level with naming convention
Parent Table:
Child Table:
Aim:
Procedure:
Student Table
STUDENTID NAME
v002 Abhay
v003 Acelin
v004 Adephos
v001 Abe
Marks Table
STUDENTID TOTALMARKS
v001 95
v002 80
v003 74
v004 81
1.Write a query to identify all students who get better marks than that of the student who's StudentID is
'v002', but we do not know the marks of 'v002'
Aim:
Procedure:
Emp table
1) Write a
query to select all record from emp where designation not in LECTURER or
ASS PROF.
2)Write a query to select all record from emp where ename in ‘KALA','BALA' and
'SUMA'.
3) Write a query to select all record from emp where ename NOT in ‘KALA','BALA' and
'SUMA'
Aim:
Procedure:
Table name : employees
COUNT()
Syntax
COUNT(*)
10
2. Write a query to count the number of records for id is 101.
COUNT(*)
3
MAX function
SQL MAX function is used to find out the record with maximum value among a record set.
MAX(DAILY_TYPING_PAGES)
690
MIN function
SQL MIN function is used to find out the record with minimum value among a record set.
MAX(DAILY_TYPING_PAGES)
60
5) Write a query use MIN Function along with MAX function to find out minimum value.
LEAST MAX
60 690
AVG function
SQL AVG function is used to find out the average of a field in various records.
AVG(DAILY_TYPING_PAGES)
426
Sum function
SQL SUM function is used to find out the sum of a field in various records.
SUM(DAILY_TYPING_PAGES)
4260
8) Write a query to find the sum up all the records related to a single person and total typed
pages by every person.
NAME SUM(DAILY_TYPING_PAGES)
raja 500
kala 1460
kumar 1250
sugi 300
mala 750
SQRT function
SQRT(16)
4
ABS(X)
ABS(-2)
2
COS(X)
COS(90)
-.44807361612917015236547731439963950742
EXP(X)
This function returns the value of e (the base of the natural logarithm) raised to the power of X.
EXP(3)
20.0855369231876677409285296545817178971
GREATEST(n1,n2,n3, ......... )
The GREATEST() function returns the greatest value in the set of input parameters (n1, n2, n3, a
nd so on).
13) Write a query to return the largest number from a set of numeric values.
GREATEST(3,5,1,8,33,99,34,55,67,43)
99
LEAST(N1,N2,N3,N4, ..... )
14)Write a query to return the least-valued item from the value list
LEAST(3,5,1,8,33,99,34,55,67,43)
1
MOD(N,M)
MOD(29,3)
2
POWER(X,Y)
POWER(3,3)
27
ASCII(str)
Returns the numeric value of the leftmost character of the string str. Returns 0 if str is the empty
string. Returns NULL if str is NULL. ASCII() works for characters with numeric values from 0 to
255.
17) Write a SQL statement to find the ASCII value of 2.
ASCII('2')
50
INSTR(str,substr)
Returns the position of the first occurrence of substring substr in string str.
18) Write a SQL statement to return the position of the first occurance of substring ‘bar’.
INSTR('FOOBARBAR','BAR')
4
LENGTH(str)
19) Write a SQL statement to find the length of the string ‘text’.
LENGTH('TEXT')
4
LOWER(str)
Returns the string str with all characters changed to lowercase according to the current character
set mapping.
20) Write a query to change the given string into lowercase letters
LOWER('COMPUTERSCIENCE')
computer science
REPLACE(str,from_str,to_str)
Returns the string str with all occurrences of the string from_str replaced by the string to_str.
REPLACE('WWW.MYSQL.COM','W','WW')
WwWwWw.mysql.com
UPPER(str)
Returns the string str with all characters changed to uppercase according to the current character
set mapping.
UPPER('computer applications')
COMPUTER APPLICATIONS
CONCAT function
SQL CONCAT function is used to concatenate two strings to form a single string.
DATE functions:
Add_months :
Syntax:
Syntax:
MONTHS_BETWEEN(date1, date2)
24) Write a SQL query to find number of months between 2 specified dates.
MONTHS_BETWEEN('01-MAR-06','01-DEC-05')
3
Next_day:
It returns the date of first day of the week specified in a string after the beginning date.
Syntax: NEXT_DAT(date,ch)
NEXT_DAY('13-MAR-05','SUNDAY')
20-MAR-05
Result :
EX.NO: 6 SET OPERATIONS
DATE:
Aim:
Procedure:
Set Operation in SQL
SQL supports few Set operations to be performed on table data. These are used to get meaningful
results from data, under different special conditions.
Union
UNION is used to combine the results of two or more Select statements. However it will eliminate
duplicate rows from its result set. In case of union, number of columns and datatype must be same
in both the tables.
select * from student1 union select * from student2
Result table
This operation is similar to Union. But it also shows the duplicate rows.
Result table
Intersect operation is used to combine two SELECT statements, but it only retuns the records
which are common from both SELECT statements. In case of Intersect the number of columns
and datatype must be same.
Result table
Minus operation combines result of two Select statements and return only those result which
belongs to first set of result.
Result table
Aim:
Procedure
SOURCE CODE
120
Result :
EX.NO:8 FIBONACCI SERIES
DATE:
Aim:
Procedure:
SOURCE CODE
declare
f1 number(3);
f2 number(3);
f3 number(3);
num number(3);
begin
f1:=0;
f2:=1; f3:=0;
num:=1;
while num<=10
loop
dbms_output.put_line(f3);
f1:=f2;
f2:=f3;
f3:=f1+f2;
num:=num+1;
13
21
34
Result :