Dbms Record
Dbms Record
-------------------------------------------------------------------------------
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);
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.
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:
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
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.
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.
Syntax:
DECLARE
age NUMBER;
verify VARCHAR2(50);
BEGIN
age := 18;
DBMS_OUTPUT.PUT_LINE(message);
END;
/
Declaring triggers and use of cursors:
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