Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
70 views

Structured Query Language

SQL is a language used to communicate with databases and manage data. It allows users to define, manipulate, control, and query data within a relational database. SQL statements are used to perform operations like querying data, inserting records, updating records, deleting records, and creating/modifying database structures and schemas. Common SQL commands include SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP.

Uploaded by

SRIKANTH. G
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views

Structured Query Language

SQL is a language used to communicate with databases and manage data. It allows users to define, manipulate, control, and query data within a relational database. SQL statements are used to perform operations like querying data, inserting records, updating records, deleting records, and creating/modifying database structures and schemas. Common SQL commands include SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, and DROP.

Uploaded by

SRIKANTH. G
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

SQL

Structured Query
Language
DBMS - Architecture
Basic Terminologies - DBMS
Database : A database is an organised collection of Data
Database Management System :

A DBMS is a software that serves as an interface between the


database and its end users or programs.

The main feature of DBMS is – Which controls the Database.


Relational Database Management System ( RDBMS )

Relational database are organized as a set of tables with columns and


rows. Relational database technology provides the most efficient and
flexible way to access structured information.
Database is any collection of electronic records that can be processed
to produce useful information. The data can be accessed, modified,
managed, controlled and organized to perform various data-
processing operations. The data is typically indexed across rows,
columns and tables that make workload processing and data
querying efficient.
A Database Management System (DBMS) is software designed to
store, retrieve, define, and manage data in a database.

An RDBMS is a type of database management system (DBMS) that


stores data in a row-based table structure which connects related data
elements.
What is SQL
• SQL stands for Structured Query Language.

• It is designed for managing data in a relational database management system


(RDBMS).

• It is pronounced as S-Q-L or sometime See-Qwell.

• SQL is a database language, it is used for database creation, deletion, fetching


rows, and modifying rows, etc.

• SQL is based on relational algebra and tuple relational calculus.

• All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, PostgreSQL, and 


SQL Server use SQL as standard database language.
Why SQL is required
SQL is required:

• To create new databases, tables and views

• To insert records in a database

• To update records in a database

• To delete records from a database

• To retrieve data from a database


What SQL does

 With SQL, we can query our database in several ways, using English-like
statements.

 With SQL, a user can access data from a relational database management
system.

 It allows the user to describe the data.

 It allows the user to define the data in the database and manipulate it when
needed.

 It allows the user to create and drop database and table.

 It allows the user to create a view, stored procedure, function in a database.

 It allows the user to set permission on tables, procedures, and views.


SQL Syntax

SQL follows some unique set of rules and guidelines called syntax.

 SQL is not case sensitive. Generally SQL keywords are written in


uppercase.

 SQL statements are dependent on text lines. We can place a single SQL
statement on one or multiple text lines.

 You can perform most of the action in a database with SQL statements.

 SQL depends on relational algebra and tuple relational calculus.


SQL statement

SQL statements are started with any of the SQL


commands/keywords like SELECT, INSERT, UPDATE, DELETE, ALTER,
DROP etc. and the statement ends with a semicolon (;).

Example of SQL statement:


Why semicolon is used after SQL statements:

Semicolon is used to separate SQL statements. It is a standard way to


separate SQL statements in a database system in which more than one SQL
statements are used in the same call.
SQL Commands
These are the some important SQL command:

SELECT : it extracts data from a database.


UPDATE : it updates data in database.
DELETE : it deletes data from database.
CREATE TABLE : it creates a new table.
ALTER TABLE : it is used to modify the table.
DROP TABLE : it deletes a table.
CREATE DATABASE : it creates a new database.
ALTER DATABASE : It is used to modify a database.
INSERT INTO : it inserts new data into a database.
CREATE INDEX : it is used to create an index (search key).
DROP INDEX : it deletes an index.
SQL Data Types

Data types are used to represent the nature of the data that can be stored in
the database table.
For example, in a particular column of a table, if we want to store a string
type of data then we will have to declare a string data type of this column.

Data types mainly classified into three categories for every database.
 String Data types
 Numeric Data types
 Date and time Data types
Data Types in MySQL
MySQL Data Types

A list of data types used in MySQL database. This is based on MySQL 8.0.

MySQL String Data Types

CHAR(Size)

It is used to specify a fixed length string that can contain numbers, letters,
and special characters. Its size can be 0 to 255 characters. Default is 1.
It is used to specify a variable length string that can
VARCHAR(Size) contain numbers, letters, and special characters. Its
size can be from 0 to 65535 characters.

It is equal to CHAR() but stores binary byte strings. Its


BINARY(Size) size parameter specifies the column length in the
bytes. Default is 1.

It is equal to VARCHAR() but stores binary byte


VARBINARY(Size) strings. Its size parameter specifies the maximum
column length in bytes.
It holds a string that can contain a maximum length of
TEXT(Size) 255 characters.

It holds a string with a maximum length of 255


TINYTEXT characters.

MEDIUMTEXT It holds a string with a maximum length of 16,777,215.

It holds a string with a maximum length of


LONGTEXT 4,294,967,295 characters.
It is used when a string object having only one
value, chosen from a list of possible values. It
ENUM(val1, val2, val3,...) contains 65535 values in an ENUM list. If you
insert a value that is not in the list, a blank value
will be inserted.

It is used to specify a string that can have 0 or


more values, chosen from a list of possible
SET( val1,val2,val3,....) values. You can list up to 64 values at one time
in a SET list.

It is used for BLOBs (Binary Large Objects). It


BLOB(size) can hold up to 65,535 bytes.
MySQL Numeric Data Types
It is used for a bit-value type. The number of bits per
BIT(Size) value is specified in size. Its size can be 1 to 64. The
default value is 1.

It is used for the integer value. Its signed range varies


from -2147483648 to 2147483647 and unsigned range
INT(size) varies from 0 to 4294967295. The size parameter
specifies the max display width that is 255.

INTEGER(size) It is equal to INT(size).


It is used to specify a floating point number. Its size
parameter specifies the total number of digits. The
FLOAT(size, d) number of digits after the decimal point is specified
by d parameter.

It is used to specify a floating point number. MySQL used


p parameter to determine whether to use FLOAT or
FLOAT(p) DOUBLE. If p is between 0 to24, the data type becomes
FLOAT (). If p is from 25 to 53, the data type becomes
DOUBLE().

It is a normal size floating point number. Its size


parameter specifies the total number of digits. The
DOUBLE(size, d) number of digits after the decimal is specified by d
parameter.
It is used to specify a fixed point number. Its size
parameter specifies the total number of digits. The
number of digits after the decimal parameter is
DECIMAL(size, d) specified by d parameter. The maximum value for the
size is 65, and the default value is 10. The maximum
value for d is 30, and the default value is 0.

DEC(size, d) It is equal to DECIMAL(size, d).

It is used to specify Boolean values true and false. Zero


BOOL is considered as false, and nonzero values are
considered as true.
MySQL Date and Time Data Types

It is used to specify date format YYYY-MM-DD. Its


DATE supported range is from '1000-01-01' to '9999-12-31'.

It is used to specify date and time combination. Its


format is YYYY-MM-DD hh:mm:ss. Its supported range
DATETIME(fsp) is from '1000-01-01 00:00:00' to 9999-12-31
23:59:59'.

It is used to specify the timestamp. Its value is stored


as the number of seconds since the Unix
epoch('1970-01-01 00:00:00' UTC). Its format is
TIMESTAMP(fsp) YYYY-MM-DD hh:mm:ss. Its supported range is from
'1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07'
UTC.
It is used to specify the time format. Its format is hh:mm:ss.
TIME(fsp) Its supported range is from '-838:59:59' to '838:59:59'

It is used to specify a year in four-digit format. Values


YEAR allowed in four digit format from 1901 to 2155, and 0000.
SQL Operators

SQL statements generally contain some reserved words or characters


that are used to perform operations such as comparison and
arithmetical operations etc. These reserved words or characters are
known as operators.

Generally there are three types of operators in SQL:

SQL Arithmetic Operators


SQL Comparison Operators
SQL Logical Operators
Example:

SQL Arithmetic Operators:

Let's assume two variables "a" and "b". Here "a" is valued 50 and "b" valued 100.

Operators Descriptions Examples

+ It is used to add containing values of both operands a+b will give 150

- It subtracts right hand operand from left hand


operand
a-b will give -50

* It multiply both operand's values a*b will give 5000

/ It divides left hand operand by right hand operand b/a will give 2

% It divides left hand operand by right hand operand


and returns reminder
b%a will give 0
SQL Comparison Operators:

Let's take two variables "a" and "b" that are valued 50 and 100.

Operator Description Example

= Examine both operands value that are equal or not, if


yes condition become true.
(a=b) is not true

!= This is used to check the value of both operands equal or


not, if not condition become true.
(a!=b) is true

<> Examines the operand's value equal or not, if values are


not equal condition is true
(a<>b) is true

> Examine the left operand value is greater than right


Operand, if yes condition becomes true
(a>b) is not true
Operator Description Example

< Examines the left operand value is less than right Operand, if yes (a<="" td="">
condition becomes true

>= Examines that the value of left operand is greater than or equal
to the value of right operand or not,if yes condition become true
(a>=b) is not true

<= Examines that the value of left operand is less than or equal to
the value of right operand or not, if yes condition becomes true
(a<=b) is true

!< Examines that the left operand value is not less than the right
operand value
(a!<="" td="">

!> Examines that the value of left operand is not greater than the
value of right operand
(a!>b) is true
SQL Logical Operators:

This is the list of logical operators used in SQL.

Operator Description
ALL this is used to compare a value to all values in another value set.

AND this operator allows the existence of multiple conditions in an SQL


statement.

ANY this operator is used to compare the value in list according to the condition.

BETWEEN this operator is used to search for values, that are within a set of values
Operator Description

IN this operator is used to compare a value to that specified list value

NOT the NOT operator reverse the meaning of any logical operator

OR this operator is used to combine multiple conditions in SQL statements

EXISTS the EXISTS operator is used to search for the presence of a row in a
specified table

LIKE this operator is used to compare a value to similar values using


wildcard operator
SQL CREATE Database
The SQL CREATE DATABASE statement is used by a developer to create a database.

Let's see the syntax of SQL CREATE DATABASE:

You might also like