Professional Documents
Culture Documents
UNIT – II
RDBMS
RDBMS stands for Relational Database Management
System.
It is the basis for SQL, and for all modern database
systems.
MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
Relation Table
in 1987
PURPOSE OF USING SQL
SQL can
Execute queries against a database
Retrieve data from a database
Insert records in a database
Update records in a database
Delete records from a database
Create new databases
Create new tables in a database
Create stored procedures in a database
Create views in a database
Set permissions on tables, procedures, and views
FEATURES OF SQL
High Performance.
High Availability.
High Security.
Management Ease.
Open Source.
TYPES OF SQL COMMANDS
1) Data definition language:- used to create, alter and
delete the database objects.
Commands : CREATE, ALTER and DROP
Data Definition Statements:
CREATE TABLE
CREATE VIEW
CREATE INDEX
ALTER TABLE
DROP TABLE
DROP VIEW
DROP INDEX
TYPES OF SQL COMMANDS CONT…
2. Data Manipulation Language:- lets user can insert, delete
or modify the data in the database.
DCL Commands:
GRANT
REVOKE
5. Data Administration Statements:- user to perform
audits and analysis on operation within the database.
COMMIT
ROLLBACK
SAVEPOINT
SET TRANSACTION
CREATING TABLE
Tables are basic building blocks in any relational
database management system.
Syntax:
SELECT column_name,column_name
FROM table_name;
Output:
Note: Single quotes should be used for string values before and after
the column_name. Eg: ‘&name’
For Example:
1 row created.
Syntax:
Program coding:
SQL>CREATE VIEW empdet AS SELECT * FROM emp;
view created
0.09 seconds
SQL> Select * from empdet;
OUTPUT
EMPNO EMPNAME DESIGNATION SALARY BONUS
------------------------------------------------------------------------------------
10678 MALIKA SYSTEM ANALYTIC 25000 300
10679 MALAR SUPPORTER 15000 150
21367 BALU COMPUTER PROGRAMMER 15600 250
45768 BELLU MANAGER 35000 500
67897 ULLU TEAM LEADER 20000 260
Syntax:
Program code:
SQL> SELECT * FROM EMP WHERE BONUS > 300;
OUTPUT
Program coding:
Syntax
Program coding:
SQL> SELECT * FROM emp WHERE SALARY > 20000 AND BONUS < 300;
OUTPUT
Syntax:
Program coding:
SQL> SELECT * FROM emp WHERE SALARY < 20000 OR BONUS < 300;
OUTPUT
Syntax:
Syntax:
Statement Description
WHERE SALARY LIKE '200%' Finds any values that start with 200
WHERE SALARY LIKE '%2' Finds any values that end with 2
Program coding:
Syntax:
Program coding:
Syntax:
SALARY
-------------
15000
15600
20000
25000
35000
CONSTRAINS
Constraints are the rules enforced on data columns on
table.
[CONSTRAINT constraint_name]
PRIMARY KEY
(column_name1,column_name2,..)
EXAMPLE
Primary Key at column level
CREATE TABLE employee
( id number(5) PRIMARY KEY,
name char(20),
dept char(10),
age number(2),
salary number(10),
location char(10)
);
Foreign Key:
Syntax:
EMPNAME SALARY
---------------- --------------
BALU 15600
BELLU 35000
MALAR 15000
MALIKA 25000
ULLU 20000
HAVING CLAUSE
Syntax:
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
EXAMPLE
The SQL statement lists the number of customers in
each country. Only include countries with more than
5 customers:
Reference Link:
https://www.w3schools.com/sql/trysql.asp?filename=tr
ysql_select_having