0% found this document useful (0 votes)
6 views

SQL

The document provides an overview of applications, data, databases, and database management systems (DBMS), including their types, characteristics, and operations. It details the differences between DBMS and Relational Database Management Systems (RDBMS), along with the history and rules of SQL, data types, constraints, and SQL commands. Additionally, it explains various SQL operations such as selection, projection, and the use of clauses like WHERE and DISTINCT.

Uploaded by

Dharini S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL

The document provides an overview of applications, data, databases, and database management systems (DBMS), including their types, characteristics, and operations. It details the differences between DBMS and Relational Database Management Systems (RDBMS), along with the history and rules of SQL, data types, constraints, and SQL commands. Additionally, it explains various SQL operations such as selection, projection, and the use of clauses like WHERE and DISTINCT.

Uploaded by

Dharini S
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SQL

What is an Application?

Application is a collection of software or list of programs combined together to


perform a specific task. There are 4 characteristics of application they are:

(i) Accuracy
(ii) Consistency
(iii) Efficiency
(iv) Security

Types of Application:

(i) Stand-alone application: Any application that is used by a single device


without any additional feature.

Characteristics: Installation required, Internet not required, Data stored locally,


Database not required.

Eg: Calculator, Paint.

(ii) Web application: Any application that is accessed through browser is known
as web application.

Characteristics: Installation not required, Internet required, Data stored


globally, Database required.

Eg: Instagram.com, Amazon.com

(iii) Client-Server application: Any Server application/ Web application is


accessed by a client application/ mobile application is known as client-server
application.

Characteristics: Installation required, Internet required, Data stored globally,


Database required.

Eg: Instagram app, WhatsApp app.

What is Data?
Data is a raw fact that describes the attributes of the entity.

What is a Database?

 Database is a place/ medium to store the data in systematic and organized way.
 We can perform four operations that can be performed in the database they are:
(i) Create/ Insert
(ii) Read/ Retrieve
(iii) Update/ Modify
(iv) Delete/ Drop
 These operations are known as CRUD operations.

What is a Database Management System?

 DBMS is a software which is used to maintain/ manage the database.


 It provides two special features they are: Security, Authorization.
 In DBMS, we can store the data in the form of Files.
 To communicate with the DBMS we use Query language.

Types of DBMS:

(i) Network Database Management System


(ii) Hierarchical Database Management System
(iii) Object Orient Database Management System
(iv) Relational Database Management System
 Other than Relational Database Management System all other types are known as
Non-RDBMS.
 95%-98% of the companies use RDBMS.

RDBMS S/W:

 MySQL
 Oracle Database
 MS SQL Server
 Postgre SQL
 SQLite
 SQL Developer
 IBM DB2
 Amazon Aurora
 Amazon RDS
 Google Cloud
 Maria DB
 Velneo
 Vantage
 Scalway
 Harper DB
 Conzept 16
 DB Vizualizer
 SQL Server

Non-RDBMS S/W:

 Mongo DB
 Cassandra
 Couchbase
 Hbase
 Amazon Dynamo DB
 Neo 4j
 Intersystem IRIS

The RDBMS S/W use SQL whereas the Non-RDBMS S/W uses NO-SQL(not-only
SQL) i.e., Scripting languages such as Java script, Type script,etc.

RDBMS and SQL was invented by IBM and currently maintained by Oracle.

What is a Relational Database Management System?

 RDBMS is a type of DBMS software used to maintain and manage the database.
 The two main features of RDBMS are: Security, Authorization.
 In RDBMS, we store the data in the form of tables.
 To communicate with the RDBMS we use Structured Query Language(SQL).
Difference b/w DBMS and RDBMS:

DBMS RDBMS
DBMS stands for Database Management RDBMS stands for Relational Database
System. Management System.
DBMS is a software used to maintain RDBMS is a type of DBMS software
and manage the database. used to maintain and manage the
database.
In DBMS, we are storing the data in file In RDBMS, we are storing the data in
format. the table format.
-+-To communicate with the DBMS, we To communicate with the RDBMS, we
are using Query language. are using Structured Query Language.

Relational Model:

 Relational Model was invented by a Data Scientist E.F.Codd(Edgar Franklin


Codd).
 In relational model the data must be stored in table format.
 Any DBMS that follows relational model will become RDBMS (or) Any DBMS that
follows the rules of E.F.Codd will become RDBMS.

Structure of Table:

 Table: The logical organization of rows and columns is called a table.


 Rows: The horizontal sectors in a table are called as rows. Rows are also called as
“Record/Tuples”.
 Columns: The vertical sectors in a table are called as columns. Columns are also
called as “Fields/ Attributes/ Identifiers”.
 Cells: Cell is the smallest unit of the table where we store the data. By intersecting the
row and column we can create the cells.

History of SQL:

 Till 1970’s all the companies were using DBMS software.


 In 1970’s, IBM invented RDMS by integrating(combine/merge) relational model with
DBMS.
 IBM invented Structured English Query Language(SEQUEL) to communicate or
interact with RDBMS.
 Later SEQUEL evolved as Structured Query Language(SQL).
 Name of the first RDBMS is “System-R”.
 In the year 1986, SQL has made as a standard language for all the RDBMS software
by ANSI(American National Standard Institute).

Rules of E.F.Codd:

 Rule 1: All the data entered into the cell must be single valued(atomic).
 Rule 2: In RDBMS, all the data should be stored in the form of tables including the
meta data.
 Rule 3: In RDBMS, data can be stored in multiple tables, if required we can establish
the connection between the tables with the help of key attributes.
 Rule 4: All the data entered into the table must be validated, if required we can
validate the data by two methods
(i) By assigning data types
(ii) By assigning constraints

Data types are mandatory whereas constraints are optional.

Data types:

Data types are used to specify what type of data or what kind of data can be stored in
the particular memory location. Data types are classified as:

(i) Char()
(ii) Varchar()/ Varchar2()
(iii) Number()
(iv) Date
(v) Timestamp
(vi) Large object:
(a) Character large object(CLOB)
(b) Binary large object(BLOB)

SQL is case insensitive language.


Char():

 It can accept ‘A-Z’, ’a-z’, special characters, ‘0-9’, Alpha numeric.


 It follows fixed length memory allocation system.
 In char(), unused memory is a memory wastage.
 It can store upto 2000 characters.
 Syntax: char(size)
 Size: It is used to specify the total number of blocks required to store the data.

Varchar():

 It can accept ‘A-Z’, ’a-z’, special characters, ‘0-9’, Alpha numeric.


 It follows variable length memory allocation system.
 In varchar(), unused memory is a free memory.
 It can store upto 2000 characters.
 Syntax: varchar(size)

Varchar2():

 Varchar2() is the updated version of varchar() which works similar to varchar(), in


varchar2() we can store upto 4000 characters.
 Syntax: varchar2(size)

Difference b/w char() and varchar():

CHAR() VARCHAR()
It follows fixed length memory allocation It follows variable length memory allocation
system. system.
The unused memory in char() is wastage The unused memory in varchar() is free
memory. memory.
It can store upto 2000 characters. It can store upto 4000 characters.

Number():

 This datatype is used to store the numeric values.


 To the number data type we can pass two arguments they are: Precision, Scale.
 Precision: It is used to specify the total number of blocks required to store the
numeric values. Precision ranges from 1 to 38.
 Scale: It is used to specify the total number of decimal/ floating values within the
precision. Scale ranges from -84 to 127. Default value of scale is 0.
 Syntax: number(precision, [scale])

Date:

 This data type is used to store the dates.


 There are two formats given by Oracle to store the date, they are:
(i) DD-MON-YY
(ii) DD-MON-YYYY
 Syntax: date

Timestamp:

 This data type is used to store the time.


 Format: HH:MI:SS
 Syntax: timestamp

Large object:

 Character large object(CLOB): This data type is used to store the huge amount of
characters upto 4GB. Syntax: clob.
 Binary large object(BLOB): This data type is used to store the binary values of
images, documents, mp3(audio files), mp4(videos) upto 4GB. Syntax: blob.

Constraint:

 Constraints are the rules given for data validation.


 Constraints are classified as:
(a) Unique
(b) Not null
(c) Check()
(d) Primary key
(e) Foreign key
(f) Default
(g) Auto Increment
(h) Binary

Unique:
Unique is a constraint which is used to specify that the column should not accept
duplicate or repeated values.

Not null:

Not null is a constraint which is used to specify that the column should not accept the
null values or it is used to specify the mandatory field.

Check():

 It is used for performing additional validation of the data.


 To the check() constraint we can pass condition as an argument(input), if the
condition is satisfied it will accept the value, if the condition is not satisfied it will
reject the value.

Default:

This constraint is used to set a default value for a column when the value is not
specified.

Auto Increment:

It is a constraint which is used to increase the value in the column by 1 automatically


when the values are not specified.

Binary:

It is a constraint which is used to specify the column to take only the binary values(0’s
and 1’s).

Primary key:

 Primary key is a constraint which is used to identify the records uniquely from the
table.
 Primary key will not accept duplicate or repeated values.
 Primary key will not accept null.
 Primary key is a combination of unique and not null constraints.
 We can have only one primary key in a table.
 Primary key is not mandatory, but highly recommended.

Foreign key:
 Foreign key is a constraint which is used to establish the connection between the
table.
 Foreign key can accept duplicate or repeated values.
 Foreign key can accept null values.
 It is not a combination of unique and not null.
 We can have any number of foreign key in the table.
 Foreign key is present in the child table but actually belongs to the parent table.
 To be a foreign key, it is mandatory that it should be the primary key in the parent
table.
 Foreign key is also known as the Referential integrity constraint.
 Until the column is present in the child table, we cannot destroy the parent table.

Overview of SQL:

 Data Definition Language (DDL)


 Data Manipulation Language (DML)
 Transaction Control Language (TCL)
 Data Control Language (DCL)
 Data Query Language (DQL)

Data Query language (DQL):

 This language is used to question the database (or) it is used retrieve the data from the
database.
 There are 4 statements in DQL, they are:
1) Select: This statement is used to retrieve the data from the table and
display the result.
2) Projection: The process of retrieving the data from the table by selecting
only the columns is known as projection. In projection, all the data under
the column will be selected by default.
3) Selection: The process of retrieving the data from the table by selecting
both rows and columns is known as selection.
4) Joins: The process of retrieving the data from the multiple table
simultaneously is known as joins.
Projection:

 The process of retrieving the data from the table by selecting only the columns is
known as projection.
 In projection, all the data under the column will be selected by default.
 Syntax:
Select */ [Distinct] Column_name/ Expression [Alias]
From Table_name;
 Order of execution:
1) From
2) Select
 From clause will start the execution.
 From clause will execute first, it will go to the database and search for the table. If the
table is present, it will put the table under execution.
 To the from clause we can pass the table name as an argument.
 Select clause will execute after the execution of from clause.
 Work of select clause is to retrieve the data from the table and display the result.
 To the select clause we can pass three arguments:
1) Asterisk (*)
2) Column name
3) Expression

Asterisk (*):

It is used to retrieve all the data from the table (or) it is used to select all the columns.

Semi colon (;):

It is used to specify the end of the statement (or) end of the query.

Basic Commands:

 To clear the screen:


Clear screen (or) cl scr
 To check the tables in the DB:
Select *
From tab;
Tab:

Tab is a meta table which consist of the details of all the tables present in the database.

 To check the column in the table:


DESC table_name
 To set 100 characters in a line and 100 lines in a page:
Set lines 100 pages 100

Expression:

 Expression is a combination of operator and operands (or) Any statement which gives
the result is known as expression.
 Expression can be written in 2 formats:
1) Col_name operator value
2) Col_name operator col_name

Access Operator:

 Whenever we are using * it should be used alone, along with * we cannot pass any
other argument.
 But whenever we need to retrieve all the data from the table along with some
additional details, we should use
Table_name . *

Alias:

 Alias is an alternative name given to the column name or expression in the result
table.
 Alias name can be written with or without using the keyword as.
 Alias name should always be single string (or) separated by underscore.
 If we want to write multiple string as alias name, it should be written or enclosed
within double quotes.

Distinct Clause:

 Distinct is a clause which is used to remove the duplicate or repeated values form the
result table.
 Distinct clause should be always the first argument in the select clause.
 We can pass multiple arguments to the distinct clause, it will remove the record if the
combination of the arguments are repeated/ duplicated.

Selection:

The process of retrieving the data from the table by selecting both rows and columns
is known as selection.

Where Clause:

 Where clause is used to filter the records.


 Where clause executes row by row.
 To the where clause, we can pass filter condition as an argument.
 Filter condition can be written in 2 format:
1) Col_name operator col_name
2) Col_name operator value/ literals

Literals:

 Literals are the values or the data in the table.


 Literals are classified into 3 types:
1) Number literal
2) Character literal
3) Date literal
 Both character and date literals should be written or enclosed within the single quotes.
 Character literals are case sensitive.
 We can write multiple conditions in the where clause with the help of logical
operators.
 Where clause will check for the condition, if the condition satisfied, it returns true else
false. It is also known as Boolean values.
 Syntax:
Select */ col_name/ expression
From table_name
Where filter_condition;
 Order of execution:
1) From
2) Where
3) Select

Operators:

 Arithmetic Operators. (+, -, *, /)


 Relational Operator. (>, <, >=, <=)
 Comparison Operator. (=, != (or) < >)
 Concatenation Operator. (||)
 Logical Operator. (AND, OR, NOT)
 Special Operators:
 IN
 NOT IN
 BETWEEN
 NOT BETWEEN
 LIKE
 NOT LIKE
 IS
 IS NOT
 Sub Query Operators:
 ALL
 ANY
 EXISTS
 NOT EXISTS
 Set Operators:
 INTERSECT
 UNION
 UNION ALL
 MINUS/ EXCEPT

You might also like