0% found this document useful (0 votes)
19 views20 pages

Dbms Record

The document discusses various SQL commands like create database, create table, insert, and select, as well as key constraints, updating tables, joining tables, creating views, and using PL/SQL. It also covers using cursors and triggers in PL/SQL. Examples are provided like adding two numbers and checking voter eligibility.

Uploaded by

yelatos527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views20 pages

Dbms Record

The document discusses various SQL commands like create database, create table, insert, and select, as well as key constraints, updating tables, joining tables, creating views, and using PL/SQL. It also covers using cursors and triggers in PL/SQL. Examples are provided like adding two numbers and checking voter eligibility.

Uploaded by

yelatos527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

DATABASE MANAGEMENT SYSTEM LAB RECORD

-------------------------------------------------------------------------------

SQL-Structured Query Language

Commands:

1.Show Database:
Shows the Total databases present in the SQL.

2.Create database:
Creates a database in SQL.

1
B.V Dushyanth
BU21CSEN0101564
3. Create table:
Creates a table in the selected database.
Create table ‘Table_name’(Attributes datatype)

4.Insert into:
Inserting values into the table.
Insert into ‘table_name’ values (add data);

To insert multiple values we use the same command.

5.Show tables:
Shows all the tables in the selected database.

2
B.V Dushyanth
BU21CSEN0101564
6.Select,From,Where:
Select:Selcts the attributes which are requested.
From : Selecting from which table in the selected
database.
Where: Filters by using the given condition.

3
B.V Dushyanth
BU21CSEN0101564
7.Desc:
It used to request information about the table.

Key Constraints:
1.Primary Key:
Ensures that a column or a set of columns contains unique
values and is used to uniquely identify each row in a table.

4
B.V Dushyanth
BU21CSEN0101564
2.Unique:
Ensures that a column or a set of column contains a unique
values but unlike a primary key it does not identify each row
uniquely.

Alter command is used for make changes in the table, like to


add columns, Delete columns, Renaming columns and Table
names.

3.Foreign key:
Is used to establish and enforce a link between the data
in two tables to control the data that can be stored in the foreign
key table.

4.Default:

Provides a default value for a column if no value is specified

5
B.V Dushyanth
BU21CSEN0101564
5.Not null:
Ensures that a column cannot contain NULL values.

6
B.V Dushyanth
BU21CSEN0101564
Updating the new Entities in a table

Using Count, Group by, Order By Keys

Count:
Counting the rows based on specific condition.

7
B.V Dushyanth
BU21CSEN0101564
Group by:
Used to group rows based on one or more columns.

Order by:
It arranges the data in ascending or descending order.

8
B.V Dushyanth
BU21CSEN0101564
Min: Gives the minimum value.

Max:
Gives the maximum value.

Average :
Gives the average of values.

9
B.V Dushyanth
BU21CSEN0101564
All The Tables After Altering, Updating

10
B.V Dushyanth
BU21CSEN0101564
Use of Joins:

INNER JOIN:
The INNER JOIN keyword selects all rows from both the tables
as long as the condition is satisfied. This keyword will create the
result-set by combining all rows from both the tables where the
condition satisfies i.e., value of the common field will be the
same.

LEFT JOIN:
This join returns all the rows of the table on the left side of the
join and matches rows for the table on the right side of the join.
For the rows for which there is no matching row on the right side,
the result-set will contain null. LEFT JOIN is also known as
LEFT OUTER JOIN.

11
B.V Dushyanth
BU21CSEN0101564
Right Joint:
RIGHT JOIN is similar to LEFT JOIN. This join returns all
the rows of the table on the right side of the join and matching
rows for the table on the left side of the join. For the rows for
which there is no matching row on the left side, the result-set will
contain null. RIGHT JOIN is also known as RIGHT OUTER
JOIN.

12
B.V Dushyanth
BU21CSEN0101564
Use of different of operators for nested sub-queries:

13
B.V Dushyanth
BU21CSEN0101564
14
B.V Dushyanth
BU21CSEN0101564
Logical Operators (e.g., AND, OR):
You can combine subqueries with logical operators to create
complex conditions.

15
B.V Dushyanth
BU21CSEN0101564
Creating Views:

You can add SQL statements and functions to a view and present
the data as if the data were coming from one single table.

A view is created with the Create view statement.

PL/Sql:
 PL/SQL stands for Procedural Language extensions to the
Structured Query Language (SQL).
 PL/SQL is a combination of SQL along with the procedural
features of programming languages.
 PL/SQL includes procedural language elements like
conditions and loops. It allows declaration of constants and
variables, procedures and functions, types and variable of
those types and triggers.

1) Start: Begin the database operation.


2) Initialize Variables: Set up any needed data structures.
3) Define Operation Parameters: Specify parameters for the
operation.
4) Specify Operation: State what you want to do (e.g., insert,
16
B.V Dushyanth
BU21CSEN0101564
update,
query).
5) Execute Statements: Run the commands in the DBMS.
6) Stop: End the operation.

Adding Two numbers using pl/sql:

Checking the age ability for voting:

Syntax:

DECLARE
age NUMBER;
verify VARCHAR2(50);
BEGIN
age := 18;

IF age >= 18 THEN


verify:= 'You are eligible to vote.';
17
B.V Dushyanth
BU21CSEN0101564
ELSE
verify:= 'You are not eligible to vote.';
END IF;

DBMS_OUTPUT.PUT_LINE(message);
END;
/
Declaring triggers and use of cursors:

Cursor: A cursor can be basically referred to as a pointer to the


context area. Context area is a memory area that is created by
Oracle when SQL statement is processed. The cursor is thus
responsible for holding the rows that have been returned by a
SQL statement. Thus the PL/SQL controls the context area by the
help of cursor. An Active set is basically the set of rows that the
cursor holds. The cursor can be of two types: Implicit Cursor, and
Explicit Cursor.
Triggers:
A Trigger is basically a program which gets automatically
executed in response to some events such as modification in the
database. Some of the events for their execution are DDL
statement, DML statement or any Database operation. Triggers
are thus stored within the database and come into action when
specific conditions match. Hence, they can be defined on any
schema, table, view etc. There are six types of triggers: BEFORE
INSERT, AFTER INSERT, BEFORE UPDATE, AFTER
UPDATE, BEFORE DELETE, and AFTER DELETE.

18
B.V Dushyanth
BU21CSEN0101564
Result: The first PL/SQL block updates the salary of customers
in the customer table and then prints out the number of
customers that were updated.

19
B.V Dushyanth
BU21CSEN0101564
The second
PL/SQL block uses an explicit cursor to fetch and display data
from the customer table.

20
B.V Dushyanth
BU21CSEN0101564

You might also like