Rdbms File Dabba
Rdbms File Dabba
OF
RELATIONAL
DATABASE
MANAGEMENT
SYSTEM (RDBMS)
2
25 INTERSECTION ALL STATEMENT 41
26 CREATE VIEW STATEMENT 42
27 CREATE INDEX STATEMENT 42
28 UNIQUE INDEX STATEMENT 43
29 DROP INDEX 45
30 PL/SQL ARCHITECTURE 46
3
INTRODUCTION
Structured Query Language( SQL)
5
insert– Used after the create command to
insert values in the table
For example:
insert into tabley values(attribute1
datatype);
:
:
:
insert into tabley values(attributen
datatype);
delete– Deletes particular rows, tuples, or
cardinality from the table
For example:
delete from tabley where condition;
update– Updates the tuples in the table
For example:
update tabley set
tuplename=’attributename’;
Triggers– Performed when particular
conditions are met on data.
7
..............................................................
Installation of SQL:
Steps to install SQL on windows 10
8
Step 3: Click on the Execute and its automatically
downloads and installs the required files .
11
2) (I) SQL Data types
An SQL developer must decide what type of data that will be
stored inside each column when creating a table. The data type
is a guideline for SQL to understand what type of data is
expected inside of each column, and it also identifies how SQL
will interact with the stored data.
13
Data type Description
A date. Format: YYYY-MM-DD. The supported
DATE
range is from '1000-01-01' to '9999-12-31'
A date and time combination. Format: YYYY-
MM-DD hh:mm:ss. The supported range is from
DATETIME'1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
(fsp) Adding DEFAULT and ON UPDATE in the
column definition to get automatic initialization
and updating to the current date and time
SQL Database
Here, we will discuss the queries and will
understand with the help of examples
Query :
Show existing databases –
Let’s consider the existing database like 22407_simranpal,
information_schema, mysql, performance_schema, rana,
sakila, sys, world . And if you want to show the exiting
database then we will use the show database query as follows:
Example:
14
.
Query:
Create a database –
Suppose we want to create a database namely a
15
Query :
Using a database –
Syntax- USE mgccollege;
Example:
16
(II) Creating a Table: Query:
Create – used to create a new table in a database.
Here datatype may be varchar, integer, date, etc.
Syntax
CREATE TABLE table_name
( column1 datatype,
column2 datatype, ....);
Example:
Query:
Describe- to describe the structure of the table
record. Syntax
Describe table_name;
Example:
17
Query:
Insert- is used to insert values into an existing
table. Syntax
INSERT INTO table_name (column1, column2, column3, ...);
Example:
18
Example:
19
Example:
20
After ALTER Table:-
21
Example:
22
● BETWEEN operator:
The BETWEEN operator selects values within a given
range. The values can be numbers, text, or dates. It is
inclusive: begin and end values are included.
Syntax: SELECT column_name(s)FROM
table_name WHERE column_name BETWEEN
value1 AND value2;
● LIKE operator:
The LIKE operator is used in a WHERE clause to
search for a specified pattern in a column. There
are two wildcards often used in conjunction with
the LIKE operator:
● The percent sign (%) represents zero, one, or
multiple characters
● The underscore sign (_) represents one, single
character Syntax:
SELECT column1, column2, ...FROM
table_name WHERE column LIKE pattern;
Example:
23
(II) Ordering the Result of a Query:
ORDER BY- The ORDER BY keyword is used to
sort the result-set in ascending or descending
order. The ORDER BY keyword sorts the records
in ascending order by default. To sort the records
in descending order, use the DESC keyword.
Syntax: SELECT column1, column2, ...FROM
table_name ORDER BY column1, column2, ...
ASC| DESC;
Example:
24
(III) AGGREGATE FUNCTIONS:
An aggregate function in SQL performs a calculation
on multiple values and returns a single value. SQL
provides many aggregate functions that include avg,
count, sum, min, max, etc. An aggregate function
ignores NULL values when it performs the
calculation, except for the count function.
(i) COUNT( ) FUNCTION
The COUNT( ) function returns the number of rows
that matches a specified criterion.
Syntax:
SELECT COUNT(column_name)FROM
table_name WHERE condition;
Example:
(ii)AVG( ) FUNCTION
The AVG( ) function returns the average
value of a numeric column.
25
Syntax:
SELECT AVG(column_name) FROM
table_name WHERE condition;
Example:
26
(IV)
Grouping the Result of a Query:
GROUP BY:
It groups rows that have the same values into summary
rows. The GROUP BY statement is often used with
aggregate functions (COUNT(), MAX(), MIN(), SUM(),
AVG()) to group the result-set by one or more columns.
Syntax:
SELECT column_name(s)FROM table_name
WHERE condition GROUP BY column_name(s)
ORDER BY column_name(s);
Example:
DELETE
The DELETE statement is used to delete
existing records in a table.
Syntax:
DELETE FROM table_name WHERE condition;
27
Example :
28
expression: It specifies a value to test if it is
NULL value.
Output:
29
MySQL Aggregate Functions
MySQL's aggregate function is used to perform
calculations on multiple values and return the result
in a single value like the average of all values, the
sum of all values, and maximum & minimum value
among certain groups of values. We mostly use the
aggregate functions with SELECT statements in the
data query languages. Syntax:
mysql> SELECT COUNT(name) FROM rana;
30
Count() Function
MySQL count() function returns the total
number of values in the expression. This
function produces all rows or only some rows
of the table based on a specified condition, and
its return type is BIGINT. It returns zero if it
does not find any matching rows. It can work
with both numeric and non-numeric data types.
Example
Suppose we want to get the total number of
employees in the employee table, we need to use the
count() function as shown in the following query:
mysql> SELECT COUNT(name) FROM rana;
Output:
31
Ordering the result of
queries Syntax:-
select * from student order by Roll_No desc;
MySQL Operators.
The MySQL IN condition is used to reduce the
use of multiple OR conditions in a SELECT,
INSERT, UPDATE and DELETE statement.
In Operator
Syntax:
32
SELECT * FROM officers WHERE
officer_name = 'Ajeet'
OR
officer_name = 'Vimal' OR
officer_name = 'Deepika';
Output:
33
Lower.
The SQL LOWER () function is used to
convert all characters of a string to lower
case. Syntax: LOWER (SQL
course)
Example:
UPPER.
The SQL UPPER () function is used to
convert all characters of a string to
uppercase. Syntax: UPPER(SQLcourse)
34
example:
Length.
This function returns the length
of the input string. Syntax:
LENGTH (Column | Expression)
Example:
CONCAT.
35
This function always appends (concatenates) string2 to
the end of string1.
Syntax: CONCAT ('String1', 'String2')
Example:
INSTR.
This function returns numeric position of a
character or a string in a given string.
Syntax: INSTR (Column | Expression, 'String', [,m],
[n]) Example
36
SUBSTR.
This function returns a portion of a string from a given
start point to an end point.
Syntax: SUBSTR ('String', start-index, length of
extracted string)
Example:
Union
ALL operator A union is used for extracting rows using
the conditions specified in the query while Union All is
used for extracting all the rows from a set of two tables.
Syntax: select column name(s) from table1 UNION
ALL Select column name(s)from table2;
37
Intersection operator
The UNION ALL command combines the result set of two
or more SELECT statements (allows duplicate values).
Syntax: select column name(s) from
table1 Intersect
Select column name(s)from table2;
38
Intersection ALL statement
39
Create index statement
Indexes are used to retrieve data from the database
more quickly than otherwise. The users cannot see the
indexes, they are just used to speed up searches/queries.
Syntax: Create index index name
ON table name (column1, column2);
40
Drop index statement
The DROP INDEX statement is used to delete an
index in a table.
Syntax: Drop index index
name ON table name;
PL/SQL Architecture
PL/SQL Functionalities
PL/SQL is not case sensitive so you are free to use lower case
letters or upper case letters except within string and character
literals. A line of PL/SQL text contains groups of characters
known as lexical units. It can be classified as follows:
○ Delimeters
○ Identifiers
○ Literals
○ Comments
Features of PL/SQL :
PL/SQL Architecture
PL/SQL can reside in two environments –
43
2. The Oracle tools
Advantages of PL/SQL :
● PL/SQL provides better performance.
● PL/SQL has high Productivity.
● It supports Object-Oriented Programming concepts.
● It has Scalability and Manageability.
● PL/SQL supports various Web Application
Development tools.
Disadvantages of PL/SQL :
44