SlideShare a Scribd company logo
1 of 111
BAIS Lab Class
Module Title: - Use Basic Structured Query Language
Module code: BAIS 3062
4/8/2024 Prepared by Instructor Mr.Elias P 1
Introduction to SQL
ā€¢ What is SQL?
ā€¢ SQL stands for Structured Query Language
ā€¢ SQL lets you access and manipulate databases
ā€¢ SQL is an ANSI (American National Standards Institute) standard
ā€¢ SQL stands for Structured Query Language.
ā€¢ SQL is a standard language for accessing and manipulating
databases.
ā€¢ SQL is a widely used database language, providing means of data
manipulation (store, retrieve, update, delete) and database
creation.
4/8/2024 Prepared by Instructor Mr.Elias P 2
Function of SQL
ā€¢ What Can SQL do?
ā€¢ SQL can execute queries against a database
ā€¢ SQL can retrieve data from a database
ā€¢ SQL can insert records in a database
ā€¢ SQL can update records in a database
ā€¢ SQL can delete records from a database
ā€¢ SQL can create new databases
ā€¢ SQL can create new tables in a database
ā€¢ SQL can create stored procedures in a database
ā€¢ SQL can create views in a database
ā€¢ SQL can set permissions on tables, procedures, and views
ā€¢ However, to be compliant with the ANSI standard, they all support at least
the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE)
in a similar manner.
ā€¢ provides a fixed set of data types in particular for strings of different
length char(n), varchar(n), longvarchar(n)
4/8/2024 Prepared by Instructor Mr.Elias P 3
SQL Commands
ļ‚§ The standard SQL commands to interact with relational databases are CREATE,
SELECT, INSERT, UPDATE, DELETE and DROP. These commands can be classified
into groups based on their nature:
ļ‚§ DDL - Data Definition Language: which defines the structure of the data
ļ‚§ DML - Data Manipulation Language: which retrieves or modifies data
ļ‚§ DCL - Data Control Language: which defines the privileges granted to database
users.
ļ‚§ DQL - Data Query Language: Retrieves certain records from one or more tables
ļ¶ DDL - Data Definition Language:
Command Description
CREATE Creates a new table, a view of a table, or other object in database
ALTER Modifies an existing database object, such as a table.
DROP Deletes an entire table, a view of a table or other object in the
database.
4/8/2024 Prepared by Instructor Mr.Elias P 4
ļ¶DML - Data Manipulation Language:
ļƒ˜ Command Description
ā€¢ INSERT Creates a record
ā€¢ UPDATE Modifies records
ā€¢ DELETE Deletes records
ļ¶ DCL - Data Control Language:
ļ‚§ Command Description
ļ‚§ GRANT Gives a privilege to user
ļ‚§ REVOKE Takes back privileges granted from user
ļ¶ DQL - Data Query Language:
ļ‚§ Command Description
ļ‚§ SELECT Retrieves certain records from one or more
tables
4/8/2024 Prepared by Instructor Mr.Elias P 5
ļƒ˜What is table?
ā€¢ The data in RDBMS is stored in database objects called tables. The table is a
collection of related data entries and it consists of columns and rows.
ā€¢ Remember, a table is the most common and simplest form of data storage in a
relational database. Following is the example of a CUSTOMERS table
ā€¢ +----+----------+-----+-----------+----------+
ā€¢ | ID | NAME | AGE | ADDRESS | SALARY |
ā€¢ +----+----------+-----+-----------+----------+
ā€¢ | 1 | Ramesh | 32 | Ahmadabad | 2000.00 |
ā€¢ | 2 | Khilan | 25 | Delhi | 1500.00 |
ā€¢ | 3 | kaushik | 23 | Kota | 2000.00 |
ā€¢ | 4 | Chaitali | 25 | Mumbai | 6500.00 |
ā€¢ | 5 | Hardik | 27 | Bhopal | 8500.00 |
ā€¢ | 6 | Komal | 22 | MP | 4500.00 |
ā€¢ | 7 | Muffy | 24 | Indore | 10000.00 |
ā€¢ +----+----------+-----+-----------+----------+
4/8/2024 Prepared by Instructor Mr.Elias P 6
ļƒ˜What is field?
ā€¢ Every table is broken up into smaller entities called fields. The
fields in the CUSTOMERS table consist of ID, NAME, AGE,
ADDRESS and SALARY.
ā€¢ A field is a column in a table that is designed to maintain specific
information about every record in the table.
ļƒ˜ What is record or row?
ā€¢ A record, also called a row of data, is each individual entry that
exists in a table. For example, there are 7 records in the above
CUSTOMERS table. Following is a single row of data or record in
the CUSTOMERS table:
ā€¢ +----+----------+-----+-----------+----------+
ā€¢ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
ā€¢ +----+----------+-----+-----------+----------+
ļ¶ A record is a horizontal entity in a table.
4/8/2024 Prepared by Instructor Mr.Elias P 7
ļƒ˜What is column?
ā€¢ A column is a vertical entity in a table that contains all information
associated with a specific field in a table.
ā€¢ For example, a column in the CUSTOMERS table is ADDRESS, which
represents location description and would consist of the following:
+-----------+
| ADDRESS |
+-----------+
| Ahmedabad |
| Delhi |
| Kota |
| Mumbai |
| Bhopal |
| MP |
| Indore |
+----+------+
4/8/2024 Prepared by Instructor Mr.Elias P 8
What is NULL value?
ā€¢ A NULL value in a table is a value in a field that appears to be
blank, which means a field with a NULL value is a field with no
value.
ā€¢ It is very important to understand that a NULL value is
different than a zero value or a field that contains spaces.
ā€¢ A field with a NULL value is one that has been left blank
during record creation.
4/8/2024 Prepared by Instructor Mr.Elias P 9
SQL Constraints:
ā€¢ Constraints: are the rules enforced on data columns on table. These are
used to limit the type of data that can go into a table. This ensures the
accuracy and reliability of the data in the database.
ā€¢ Constraints could be column level or table level. Column level constraints
are applied only to one column, whereas table level constraints are
applied to the whole table.
ļ¶ Following are commonly used constraints available in SQL:
ā€¢ NOT NULL Constraint: Ensures that a column cannot have NULL value.
ā€¢ DEFAULT Constraint: Provides a default value for a column when none is
specified.
ā€¢ PRIMARY Key: Uniquely identified each rows/records in a database table.
ā€¢ FOREIGN Key: Uniquely identified a rows/records in any another database
table.
ā€¢ UNIQUE Constraint: Ensures that all values in a column are different.
ā€¢ CHECK Constraint: The CHECK constraint ensures that all values in a
column satisfy certain conditions.
ā€¢ INDEX: Use to create and retrieve data from the database very quickly.
4/8/2024 Prepared by Instructor Mr.Elias P 10
Data Integrity:
ļ¶ The following categories of the data integrity exist with each
RDBMS:
ā€¢ Entity Integrity : There are no duplicate rows in a table.
ā€¢ Domain Integrity : Enforces valid entries for a given column by
restricting the type, the format, or the range of values.
ā€¢ Referential Integrity : Rows cannot be deleted which are used
by other records.
ā€¢ User-Defined Integrity : Enforces some specific business rules
that do not fall into entity, domain, or referential integrity.
4/8/2024 Prepared by Instructor Mr.Elias P 11
SQL Syntax
ā€¢ SQL is followed by unique set of rules and guidelines called
Syntax. This tutorial gives you a quick start with SQL by listing
all the basic SQL Syntax:
ā€¢ All the SQL statements start with any of the keywords like
SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE,
SHOW and all the statements end with a semicolon (;).
ā€¢ Important point to be noted is that SQL is case insensitive,
which means SELECT and select have same meaning in SQL
statements, but My SQL makes difference in table names. So if
you are working with My SQL, then you need to give table
names as they exist in the database.
4/8/2024 Prepared by Instructor Mr.Elias P 12
1. PRIMARY KEY
ā€¢ The PRIMARY KEY:-constraint uniquely identifies each record in a
database table.
ā€¢ A primary key is a field in a table which uniquely identifies each
row/record in a database table. Primary keys must contain unique
values. A primary key column cannot have NULL values.
ā€¢ A table can have only one primary key, which may consist of single
or multiple fields. When multiple fields are used as a primary key,
they are called a composite key.
ā€¢ If a table has a primary key defined on any field(s), then you can not
have two records having the same value of that field(s).
ā€¢ Note: You would use these concepts while creating database tables.
ā€¢ Create Primary Key:
ā€¢ Here is the syntax to define ID attribute as a primary key in a
CUSTOMERS table
4/8/2024 Prepared by Instructor Mr.Elias P 13
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL,
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2),
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 14
2. NOT NULL Constraint:
ā€¢ By default, a column can hold NULL values. If you do not want
a column to have a NULL value, then you need to define such
constraint on this column specifying that NULL is now not
allowed for that column.
ā€¢ A NULL is not the same as no data, rather, it represents
unknown data. Example:
ā€¢ For example, the following SQL creates a new table called
CUSTOMERS and adds five columns, three of which, ID and
NAME and AGE, specify not to accept NULLs:
4/8/2024 Prepared by Instructor Mr.Elias P 15
Contiā€¦
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL,
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2),
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 16
3.DEFAULT Constraint:
ā€¢ The DEFAULT constraint provides a default value to a
column when the INSERT INTO statement does not
provide a specific value.
ā€¢ Example: For example, the following SQL creates a
new table called CUSTOMERS and adds five columns.
ā€¢ Here, SALARY column is set to 5000.00 by default, so
in case INSERT INTO statement does not provide a
value for this column. then by default this column
would be set to 5000.00.
4/8/2024 Prepared by Instructor Mr.Elias P 17
Contiā€¦.
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL,
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2) DEFAULT 5000.00,
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 18
4.UNIQUE Constraint:
ā€¢ The UNIQUE Constraint prevents two records
from having identical values in a particular
column.
ā€¢ In the CUSTOMERS table, for example, you might
want to prevent two or more people from having
identical age. Example:
ā€¢ For example, the following SQL creates a new
table called CUSTOMERS and adds five columns.
Here, AGE column is set to UNIQUE, so that you
can not have two records with same age:
4/8/2024 Prepared by Instructor Mr.Elias P 19
Contiā€¦.
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL UNIQUE,
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2),
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 20
5.FOREIGN Key:
ā€¢ A foreign key is a key used to link two tables together.
ā€¢ This is sometimes called a referencing key.
ā€¢ Foreign Key is a column or a combination of columns whose
values match a Primary Key in a different table.
ā€¢ The relationship between 2 tables matches the Primary Key
in one of the tables with a Foreign Key in the second table.
ā€¢ If a table has a primary key defined on any field(s), then you
can not have two records having the same value of that
field(s). Example:
ā€¢ Consider the structure of the two tables as follows:
4/8/2024 Prepared by Instructor Mr.Elias P 21
CUSTOMERS table:
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL,
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2),
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 22
ORDERS table:
ā€¢ CREATE TABLE ORDERS (
ā€¢ ID INT NOT NULL,
ā€¢ DATE DATETIME,
ā€¢ CUSTOMER_ID INT references CUSTOMERS(ID),
ā€¢ AMOUNT double,
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 23
6.CHECK Constraint:
ā€¢ The CHECK Constraint enables a condition to check
the value being entered into a record.
ā€¢ If the condition evaluates to false, the record
violates the constraint and isnā€™t entered into the
table.
ā€¢ Example: For example, the following SQL creates a
new table called CUSTOMERS and adds five columns.
ā€¢ Here, we add a CHECK with AGE column, so that you
can not have any CUSTOMER below 18 years:
4/8/2024 Prepared by Instructor Mr.Elias P 24
Contiā€¦.
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL CHECK (AGE >= 18),
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2),
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 25
7. INDEX:
ā€¢ The INDEX is used to create and retrieve data from
the database very quickly. Index can be created by
using single or group of columns in a table.
ā€¢ When index is created, it is assigned a ROWID for
each row before it sorts out the data.
ā€¢ Proper indexes are good for performance in large
databases, but you need to be careful while creating
index.
ā€¢ Selection of fields depends on what you are using in
your SQL queries. Example: For example, the
following SQL creates a new table called CUSTOMERS
and adds five columns:
4/8/2024 Prepared by Instructor Mr.Elias P 26
Contiā€¦.
ā€¢ CREATE TABLE CUSTOMERS(
ā€¢ ID INT NOT NULL,
ā€¢ NAME VARCHAR (20) NOT NULL,
ā€¢ AGE INT NOT NULL,
ā€¢ ADDRESS CHAR (25) ,
ā€¢ SALARY DECIMAL (18, 2),
ā€¢ PRIMARY KEY (ID)
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 27
Contiā€¦
ā€¢ Now, you can create index on single or multiple
columns using the following syntax:
ā€¢ CREATE INDEX index_name
ā€¢ ON table_name ( column1, column2.....);
ā€¢ To create an INDEX on AGE column, to optimize the
search on customers for a particular age, following is
the SQL syntax:
ā€¢ CREATE INDEX idx_age
ā€¢ ON CUSTOMERS ( AGE );
4/8/2024 Prepared by Instructor Mr.Elias P 28
1.SQL CREATE Database
ā€¢ The SQL CREATE DATABASE statement is used to
create new SQL database.
ā€¢ Syntax: Basic syntax of CREATE DATABASE statement
is as follows:
ā€¢ CREATE DATABASE Database Name;
ā€¢ Always database name should be unique within the
RDBMS. Example:
ā€¢ If you want to create new database <testDB>, then
CREATE DATABASE statement would be as follows:
4/8/2024 Prepared by Instructor Mr.Elias P 29
Conti..
ā€¢ SQL> CREATE DATABASE test DB;
ā€¢ Make sure you have admin privilege before creating
any database.
ā€¢ Once a database is created, you can check it in the
list of databases as follows:
4/8/2024 Prepared by Instructor Mr.Elias P 30
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 31
2. DROP or DELETE Database
ā€¢ The SQL DROP DATABASE statement is used to drop
an existing database in SQL schema.
ā€¢ Syntax: Basic syntax of DROP DATABASE statement is
as follows:
ā€¢ DROP DATABASE Data base Name;
ā€¢ Always database name should be unique within the
RDBMS.
ā€¢ Example: If you want to delete an existing database
<test DB>, then DROP DATABASE statement would be
as follows:
ā€¢ SQL> DROP DATABASE test DB;
4/8/2024 Prepared by Instructor Mr.Elias P 32
Contiā€¦.
ā€¢ NOTE: Be careful before using this operation
because by deleting an existing database
would result in loss of complete information
stored in the database.
ā€¢ Make sure you have admin privilege before
dropping any database.
ā€¢ Once a database is dropped, you can check it.
4/8/2024 Prepared by Instructor Mr.Elias P 33
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 34
3.SQL SELECT Database
ā€¢ The SELECT statement is probably the most used
SQL command.
ā€¢ The SELECT statement is used for retrieving rows
from
the database and enables the selection of one or
many rows or columns from one or many tables in
the database.
4/8/2024 Prepared by Instructor Mr.Elias P 35
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 36
EXAMPLE
4/8/2024 Prepared by Instructor Mr.Elias P 37
Conti..
4/8/2024 Prepared by Instructor Mr.Elias P 38
4.SQL CREATE Table
ā€¢ Creating a basic table involves naming the
table and defining its columns and each
column's data type.
ā€¢ The SQL CREATE TABLE statement is used to
create a new table.
ā€¢ Syntax: Basic syntax of CREATE TABLE
statement is as follows:
4/8/2024 Prepared by Instructor Mr.Elias P 39
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 40
5.SQL DROP or DELETE Table
ā€¢ The SQL DROP TABLE statement is used to remove a table
definition and all data, indexes, triggers, constraints, and
permission specifications for that table.
ā€¢ NOTE: You have to be careful while using this command
because once a table is deleted then all the information
available in the table would also be lost forever.
ā€¢ Syntax: Basic syntax of DROP TABLE statement is as follows:
ā€¢ DROP TABLE table_name;
ā€¢ SQL> DROP TABLE CUSTOMERS; Query OK, 0 rows affected
(0.01 sec)
4/8/2024 Prepared by Instructor Mr.Elias P 41
6. SQL INSERT Query
ā€¢ The SQL INSERT INTO Statement is used to add new
rows of data to a table in the database.
ā€¢ Syntax: There are two basic syntaxes of INSERT INTO
statement as follows:
ā€¢ INSERT INTO TABLE_NAME (column1, column2,
column3,...columnN)]
ā€¢ VALUES (value1, value2, value3,...valueN);
4/8/2024 Prepared by Instructor Mr.Elias P 42
Contiā€¦
ā€¢ Here, column1, column2,...columnN are the names of the
columns in the table into which you want to insert data.
ā€¢ You may not need to specify the column(s) name in the
SQL query if you are adding values for all the columns of
the table.
ā€¢ But make sure the order of the values is in the same
order as the columns in the table.
ā€¢ The SQL INSERT INTO syntax would be as follows:
ā€¢ INSERT INTO TABLE_NAME VALUES
(value1,value2,value3,...valueN);
4/8/2024 Prepared by Instructor Mr.Elias P 43
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 44
ā€¢ You can create a record in CUSTOMERS table using
second syntax as follows:
ā€¢ INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24,
'Indore', 10000.00 );
4/8/2024 Prepared by Instructor Mr.Elias P 45
Contiā€¦..
4/8/2024 Prepared by Instructor Mr.Elias P 46
7. SQL SELECT Query
ā€¢ SQL SELECT Statement is used to fetch the data from a
database table which returns data in the form of result
table.
ā€¢ These result tables are called result-sets.
ā€¢ Syntax: The basic syntax of SELECT statement is as follows:
ā€¢ SELECT column1, column2, columnN FROM table_name;
ā€¢ Here, column1, column2...are the fields of a table whose
values you want to fetch.
ā€¢ If you want to fetch all the fields available in the field, then
you can use the following syntax:
ā€¢ SELECT * FROM table_name;
4/8/2024 Prepared by Instructor Mr.Elias P 47
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 48
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 49
8. SQL WHERE Clause
ā€¢ The SQL WHERE clause is used to specify a condition while fetching
the data from single table or joining with multiple tables.
If the given condition is satisfied, then only it returns specific value
from the table. You would use WHERE clause
to filter the records and fetching only necessary records.
The WHERE clause is not only used in SELECT statement, but it is also
used in UPDATE, DELETE statement,
etc., which we would examine in subsequent chapters.
Syntax:
The basic syntax of SELECT statement with WHERE clause is as follows:
SELECT column1, column2, columnN
FROM table_name
WHERE [condition]
You can specify a condition using comparison or logical operators like >,
<, =, LIKE, NOT etc. Below examples
would make this concept clear.
4/8/2024 Prepared by Instructor Mr.Elias P 50
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 51
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 52
9. SQL AND And OR Operators
ā€¢ The SQL AND and OR operators are used to combine multiple
conditions to narrow data in an SQL
statement.
ā€¢ These two operators are called conjunctive operators.
These operators provide a means to make multiple comparisons
with different operators in the same SQL
statement.
The AND Operator:
The AND operator allows the existence of multiple conditions in an
SQL statement's WHERE clause.
Syntax:
The basic syntax of AND operator with WHERE clause is as follows:
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];
You can combine N number of conditions using AND operator. For
an action to be taken by the SQL statement,
whether it be a transaction or query, all conditions separated by the
AND must be TRUE.
4/8/2024 Prepared by Instructor Mr.Elias P 53
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 54
Contiā€¦..
4/8/2024 Prepared by Instructor Mr.Elias P 55
The OR Operator:
ā€¢ The OR operator is used to combine multiple conditions
in an SQL statement's WHERE clause.
Syntax:
The basic syntax of OR operator with WHERE clause is as
follows:
SELECT column1, column2, columnN
FROM table_name
WHERE [condition1] OR [condition2]...OR [conditionN]
You can combine N number of conditions using OR
operator. For an action to be taken by the SQL
statement,
whether it be a transaction or query, only any ONE of
the conditions separated by the OR must be TRUE.
4/8/2024 Prepared by Instructor Mr.Elias P 56
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 57
10.SQL UPDATE Query
ā€¢ The SQL UPDATE Query is used to modify the existing
records in a table.
You can use WHERE clause with UPDATE query to update
selected rows, otherwise all the rows would be
affected.
Syntax:
The basic syntax of UPDATE query with WHERE clause is as
follows:
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN =
valueN
WHERE [condition];
You can combine N number of conditions using AND or OR
operators.
4/8/2024 Prepared by Instructor Mr.Elias P 58
Example
4/8/2024 Prepared by Instructor Mr.Elias P 59
Contiā€¦ā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 60
11. ALTER TABLE
ā€¢ The ALTER TABLE statement is used to add, delete, or
modify columns in an existing table.
ā€¢ To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype
ā€¢ To delete a column in a table, use the following syntax
(notice that some database systems don't allow deleting a
column):
ā€¢ ALTER TABLE table_name
DROP COLUMN column_name
ā€¢ To change the data type of a column in a table, use the
following syntax:
ALTER TABLE table_name
ALTER COLUMN column_name datatype
4/8/2024 Prepared by Instructor Mr.Elias P 61
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 62
Contiā€¦..
4/8/2024 Prepared by Instructor Mr.Elias P 63
12. SQL TRUNCATE TABLE
ā€¢ The SQL TRUNCATE TABLE command is used to delete
complete data from an existing table.
ā€¢ You can also use DROP TABLE command to delete
complete table but it would remove complete table
structure form the database and you would need to re-
create this table once again if you wish you store some
data.
Syntax:
The basic syntax of TRUNCATE TABLE is as follows:
TRUNCATE TABLE table_name;
4/8/2024 Prepared by Instructor Mr.Elias P 64
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 65
13. SQL DELETE Query
ā€¢ The SQL DELETE Query is used to delete the
existing records from a table.
ā€¢ You can use WHERE clause with DELETE query to
delete selected rows, otherwise all the records
would be deleted.
Syntax:
ā€¢ The basic syntax of DELETE query with WHERE
clause is as follows:
ā€¢ DELETE FROM table_name
WHERE [condition];
ā€¢ You can combine N number of conditions using
AND or OR operators.
4/8/2024 Prepared by Instructor Mr.Elias P 66
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 67
Contiā€¦ā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 68
14. SQL LIKE Clause
ā€¢ The SQL LIKE clause is used to compare a value to
similar values using wildcard operators.
ā€¢ There are two wildcards used in conjunction with the
LIKE operator:
The percent sign (%)
The underscore (_)
The percent sign represents zero, one, or multiple
characters.
ā€¢ The underscore represents a single number or
character.
ā€¢ The symbols can be used in combinations.
4/8/2024 Prepared by Instructor Mr.Elias P 69
Syntax:
ā€¢ The basic syntax of % and _ is as follows:
SELECT FROM table_name
WHERE column LIKE 'XXXX%'
or
SELECT FROM table_name
WHERE column LIKE '%XXXX%'
or
SELECT FROM table_name
WHERE column LIKE 'XXXX_'
or
SELECT FROM table_name
WHERE column LIKE '_XXXX'
or
SELECT FROM table_name
WHERE column LIKE '_XXXX_ā€˜
ā€¢ You can combine N number of conditions using AND or OR operators. Here, XXXX
could be any numeric or string value.
4/8/2024 Prepared by Instructor Mr.Elias P 70
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 71
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 72
Example
4/8/2024 Prepared by Instructor Mr.Elias P 73
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 74
15. SQL TOP Clause
ā€¢ The SQL TOP clause is used to fetch a TOP N number or
X percent records from a table.
Note: All the databases do not support TOP clause. For
example MySQL supports LIMIT clause to fetch limited
number of records and Oracle uses ROWNUM to fetch
limited number of records.
Syntax:
The basic syntax of TOP clause with SELECT statement
would be as follows:
SELECT TOP number|percent column_name(s)
FROM table_name
WHERE [condition]
4/8/2024 Prepared by Instructor Mr.Elias P 75
Example
4/8/2024 Prepared by Instructor Mr.Elias P 76
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 77
16. SQL ORDER BY Clause
ā€¢ The SQL ORDER BY clause is used to sort the data in
ascending or descending order, based on one or
more columns. Some database sorts query results in
ascending order by default.
Syntax:
The basic syntax of ORDER BY clause is as follows:
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
You can use more than one column in the ORDER BY clause.
ā€¢ Make sure whatever column you are using to sort,
that column should be in column-list.
4/8/2024 Prepared by Instructor Mr.Elias P 78
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 79
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 80
17. SQL Distinct Keyword
ā€¢ The SQL DISTINCT keyword is used in conjunction with
SELECT statement to eliminate all the duplicate
records and fetching only unique records.
There may be a situation when you have multiple duplicate
records in a table. While fetching such records, it
makes more sense to fetch only unique records instead of
fetching duplicate records.
Syntax:
The basic syntax of DISTINCT keyword to eliminate
duplicate records is as follows:
SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]
4/8/2024 Prepared by Instructor Mr.Elias P 81
Example:
4/8/2024 Prepared by Instructor Mr.Elias P 82
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 83
18. SQL Joins
ā€¢ The SQL Joins clause is used to combine
records from two or more tables in a
database.
ā€¢ A JOIN is a means for combining fields from
two tables by using values common to each.
4/8/2024 Prepared by Instructor Mr.Elias P 84
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 85
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 86
SQL Join Types:
ā€¢ There are different types of joins available in SQL:
ā€¢ INNER JOIN: returns rows when there is a match
in both tables.
ā€¢ LEFT JOIN: returns all rows from the left table,
even if there are no matches in the right table.
ā€¢ RIGHT JOIN: returns all rows from the right table,
even if there are no matches in the left table.
ā€¢ FULL JOIN: returns rows when there is a match in
one of the tables.
4/8/2024 Prepared by Instructor Mr.Elias P 87
INNER JOIN
ā€¢ The most frequently used and important of the joins is
the INNER JOIN.
ā€¢ They are also referred to as an EQUIJOIN.
ā€¢ The INNER JOIN creates a new result table by
combining column values of two tables (table1 and
table2) based upon the join-predicate.
ā€¢ The query compares each row of table1 with each row
of table2 to find all pairs of rows which satisfy the join-
predicate.
ā€¢ When the join-predicate is satisfied, column values for
each matched pair of rows of A and B are combined
into a result row.
4/8/2024 Prepared by Instructor Mr.Elias P 88
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 89
(b) Another table is ORDERS as follows:
4/8/2024 Prepared by Instructor Mr.Elias P 90
LEFT JOIN
ā€¢ The SQL LEFT JOIN returns all rows from the left
table, even if there are no matches in the right
table.
ā€¢ This means that if the ON clause matches 0 (zero)
records in right table, the join will still return a
row in the result, but with NULL in each column
from right table.
ā€¢ This means that a left join returns all the values
from the left table, plus matched values from the
right table or NULL in case of no matching join
predicate.
4/8/2024 Prepared by Instructor Mr.Elias P 91
Contiā€¦..
4/8/2024 Prepared by Instructor Mr.Elias P 92
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 93
Contiā€¦..
4/8/2024 Prepared by Instructor Mr.Elias P 94
RIGHT JOIN
ā€¢ The SQL RIGHT JOIN returns all rows from the
right table, even if there are no matches in the
left table.
ā€¢ This means that if the ON clause matches 0 (zero)
records in left table, the join will still return a row
in the result, but with NULL in each column from
left table.
ā€¢ This means that a right join returns all the values
from the right table, plus matched values from
the left table or NULL in case of no matching join
predicate.
4/8/2024 Prepared by Instructor Mr.Elias P 95
Contiā€¦.
ā€¢ Syntax: The basic syntax of RIGHT JOIN is as
follows:
ā€¢ SELECT table1.column1, table2.column2...
FROM table1 RIGHT JOIN table2 ON
table1.common_filed = table2.common_field;
ā€¢ Example: Consider the following two tables,
(a) CUSTOMERS table is as follows:
4/8/2024 Prepared by Instructor Mr.Elias P 96
Contiā€¦.
4/8/2024 Prepared by Instructor Mr.Elias P 97
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 98
FULL JOIN
ā€¢ The SQL FULL JOIN combines the results of both left
and right outer joins.
ā€¢ The joined table will contain all records from both
tables, and fill in NULLs for missing matches on either
side.
ā€¢ Syntax:
ā€¢ The basic syntax of FULL JOIN is as follows:
ā€¢ SELECT table1.column1, table2.column2... FROM
table1 FULL JOIN table2 ON table1.common_filed =
table2.common_field;
ā€¢ Here given condition could be any given expression
based on your requirement.
4/8/2024 Prepared by Instructor Mr.Elias P 99
example
4/8/2024 Prepared by Instructor Mr.Elias P 100
Contiā€¦
4/8/2024 Prepared by Instructor Mr.Elias P 101
Contiā€¦ā€¦.
ā€¢ If your Database does not support FULL JOIN like
MySQL does not support FULL JOIN, then you can
use UNION ALL clause to combine two JOINS as
follows:
ā€¢ SQL> SELECT ID, NAME, AMOUNT, DATE FROM
CUSTOMERS LEFT JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID
UNION
ALL SELECT ID, NAME, AMOUNT, DATE FROM
CUSTOMERS RIGHT JOIN ORDERS ON
CUSTOMERS.ID = ORDERS.CUSTOMER_ID
4/8/2024 Prepared by Instructor Mr.Elias P 102
SQL Syntax
ā€¢ SQL is followed by unique set of rules and guidelines called
Syntax. This tutorial gives you a quick start with SQL by
listing all the basic SQL Syntax:
ā€¢ All the SQL statements start with any of the keywords like
SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE,
USE, SHOW and all the statements end with a semicolon (;).
ā€¢ Important point to be noted is that SQL is case insensitive,
which means SELECT and select have same meaning in SQL
statements, but MySQL makes difference in table names.
So if you are working with MySQL, then you need to give
table names as they exist in the database.
4/8/2024 Prepared by Instructor Mr.Elias P 103
1. SQL SELECT Statement:
ā€¢ SELECT column1, column2....columnN FROM
table_name;
ā€¢ 2. SQL INSERT INTO Statement:
ā€¢ INSERT INTO table_name( column1,
column2....columnN) VALUES ( value1,
value2....valueN);
ā€¢ 3. SQL UPDATE Statement:
ā€¢ UPDATE table_name SET column1 = value1,
column2 = value2....columnN=valueN [ WHERE
CONDITION ];
4/8/2024 Prepared by Instructor Mr.Elias P 104
4. SQL DELETE Statement:
ā€¢ DELETE FROM table_name WHERE
{CONDITION};
ā€¢ 5. SQL CREATE DATABASE Statement:
ā€¢ CREATE DATABASE database_name;
ā€¢ 6. SQL DROP DATABASE Statement:
ā€¢ DROP DATABASE database_name;
ā€¢ 7. SQL USE Statement:
ā€¢ USE DATABASE database_name;
4/8/2024 Prepared by Instructor Mr.Elias P 105
8. SQL INSERT INTO Statement:
ā€¢ INSERT INTO table_name( column1,
column2....columnN) VALUES ( value1,
value2....valueN);
ā€¢ 9. SQL ALTER TABLE Statement (Rename):
ā€¢ ALTER TABLE table_name RENAME TO
new_table_name;
ā€¢ 10. SQL ALTER TABLE Statement:
ā€¢ ALTER TABLE table_name {ADD|DROP|MODIFY}
column_name {data_ype};
4/8/2024 Prepared by Instructor Mr.Elias P 106
11. SQL TRUNCATE TABLE Statement:
ā€¢ TRUNCATE TABLE table_name;
ā€¢ 12. SQL CREATE TABLE Statement:
ā€¢ CREATE TABLE table_name(
ā€¢ column1 datatype, column2 datatype,
column3 datatype, ..... columnN datatype,
PRIMARY KEY( one or more columns )
ā€¢ );
4/8/2024 Prepared by Instructor Mr.Elias P 107
13. SQL COUNT Clause:
ā€¢ SELECT COUNT(column_name) FROM
table_name WHERE CONDITION;
ā€¢ 14. SQL ORDER BY Clause:
ā€¢ SELECT column1, column2....columnN FROM
table_name WHERE CONDITION ORDER BY
column_name {ASC|DESC};
ā€¢ 15. SQL LIKE Clause:
ā€¢ SELECT column1, column2....columnN FROM
table_name WHERE column_name LIKE {
PATTERN };
4/8/2024 Prepared by Instructor Mr.Elias P 108
16. SQL BETWEEN Clause:
ā€¢ SELECT column1, column2....columnN FROM
table_name WHERE column_name BETWEEN
val-1 AND val-2;
ā€¢ 17. SQL AND/OR Clause:
ā€¢ SELECT column1, column2....columnN FROM
table_name WHERE CONDITION-1 {AND|OR}
CONDITION-2;
4/8/2024 Prepared by Instructor Mr.Elias P 109
18. SQL DISTINCT Clause:
ā€¢ SELECT DISTINCT column1,
column2....columnN FROM table_name;
ā€¢ 19. SQL WHERE Clause:
ā€¢ SELECT column1, column2....columnN FROM
table_name WHERE CONDITION;
4/8/2024 Prepared by Instructor Mr.Elias P 110
ā€¢THE END !!!
ā€¢THANK YOU .
ā€¢IF YOU HAVE ANY
QUESTION WELL
COME!!
4/8/2024 Prepared by Instructor Mr.Elias P 111

More Related Content

Similar to Database Akjljljlkjlkjkljlkjldiministration.pptx

Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusChhom Karath
Ā 
Sql introduction
Sql introductionSql introduction
Sql introductionBhavya Chawla
Ā 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptxMohamedNowfeek1
Ā 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptxNilamHonmane
Ā 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
Ā 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query LanguageRohit Bisht
Ā 
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfComplete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfssuserb5bb0e
Ā 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
Ā 
Manage schema object.ppt
Manage schema object.pptManage schema object.ppt
Manage schema object.pptAhmadUsman79
Ā 
Advanced_SQL_Presentation_Template.pptx
Advanced_SQL_Presentation_Template.pptxAdvanced_SQL_Presentation_Template.pptx
Advanced_SQL_Presentation_Template.pptxSARASCHANDRA MAVALLAPALLI
Ā 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfDraguClaudiu
Ā 
Oracle 12c New Features for Developers
Oracle 12c New Features for DevelopersOracle 12c New Features for Developers
Oracle 12c New Features for DevelopersCompleteITProfessional
Ā 

Similar to Database Akjljljlkjlkjkljlkjldiministration.pptx (20)

sql-commands.pdf
sql-commands.pdfsql-commands.pdf
sql-commands.pdf
Ā 
Sql commands
Sql commandsSql commands
Sql commands
Ā 
Sql commands
Sql commandsSql commands
Sql commands
Ā 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
Ā 
Sql introduction
Sql introductionSql introduction
Sql introduction
Ā 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Ā 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Ā 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
Ā 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
Ā 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
Ā 
Les10.ppt
Les10.pptLes10.ppt
Les10.ppt
Ā 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query Language
Ā 
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdfComplete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Complete SQL Tutorial In Hindi By Rishabh Mishra.pdf
Ā 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
Ā 
Manage schema object.ppt
Manage schema object.pptManage schema object.ppt
Manage schema object.ppt
Ā 
Advanced_SQL_Presentation_Template.pptx
Advanced_SQL_Presentation_Template.pptxAdvanced_SQL_Presentation_Template.pptx
Advanced_SQL_Presentation_Template.pptx
Ā 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
Ā 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
Ā 
Oracle 12c New Features for Developers
Oracle 12c New Features for DevelopersOracle 12c New Features for Developers
Oracle 12c New Features for Developers
Ā 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Ā 

More from EliasPetros

ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptxghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptxEliasPetros
Ā 
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptxL04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptxEliasPetros
Ā 
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.pptlkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.pptEliasPetros
Ā 
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptxehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptxEliasPetros
Ā 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxEliasPetros
Ā 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxEliasPetros
Ā 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxEliasPetros
Ā 
Python.pptx
Python.pptxPython.pptx
Python.pptxEliasPetros
Ā 
Chapter 08.pptx
Chapter 08.pptxChapter 08.pptx
Chapter 08.pptxEliasPetros
Ā 
chaptet 4 DC and CN.ppt
chaptet 4 DC and CN.pptchaptet 4 DC and CN.ppt
chaptet 4 DC and CN.pptEliasPetros
Ā 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptxEliasPetros
Ā 
chapter 1 DC and CN-1.ppt
chapter 1 DC and CN-1.pptchapter 1 DC and CN-1.ppt
chapter 1 DC and CN-1.pptEliasPetros
Ā 

More from EliasPetros (12)

ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptxghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
ghgfjfhgdjfdhgdhgfdgfdhgdhgfdhgzeka.pptx
Ā 
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptxL04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
L04 - Control Structuresjhgjhgjhgjhgfjgfjhgfjgf.pptx
Ā 
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.pptlkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
lkjhlkjhjhkjhlkjhkjhkjhkjhkjhkjhjhkjh.ppt
Ā 
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptxehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
ehhhhhhhhhhhhhhhhhhhhhhhhhjjjjjllaye.pptx
Ā 
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptxhjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
hjkjlboiupoiuuouoiuoiuoiuoiuoiuoippt.pptx
Ā 
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptxhjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
hjksjdhksjhcksjhckjhskdjhcskjhckjdppt.pptx
Ā 
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptxMy lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
My lablkxjlkxjcvlxkcjvlxckjvlxck ppt.pptx
Ā 
Python.pptx
Python.pptxPython.pptx
Python.pptx
Ā 
Chapter 08.pptx
Chapter 08.pptxChapter 08.pptx
Chapter 08.pptx
Ā 
chaptet 4 DC and CN.ppt
chaptet 4 DC and CN.pptchaptet 4 DC and CN.ppt
chaptet 4 DC and CN.ppt
Ā 
5_6278455688045789623.pptx
5_6278455688045789623.pptx5_6278455688045789623.pptx
5_6278455688045789623.pptx
Ā 
chapter 1 DC and CN-1.ppt
chapter 1 DC and CN-1.pptchapter 1 DC and CN-1.ppt
chapter 1 DC and CN-1.ppt
Ā 

Recently uploaded

BPP NC II Lesson 3 - Pastry Products.pptx
BPP NC II Lesson 3 - Pastry Products.pptxBPP NC II Lesson 3 - Pastry Products.pptx
BPP NC II Lesson 3 - Pastry Products.pptxmaricel769799
Ā 
(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
Ā 
VIP Call Girls In Singar Nagar ( Lucknow ) šŸ” 8923113531 šŸ” Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow  ) šŸ” 8923113531 šŸ”  Cash Payment Avai...VIP Call Girls In Singar Nagar ( Lucknow  ) šŸ” 8923113531 šŸ”  Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow ) šŸ” 8923113531 šŸ” Cash Payment Avai...anilsa9823
Ā 
NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...Amil baba
Ā 
(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...ranjana rawat
Ā 
(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...ranjana rawat
Ā 
Russian Call Girls in Nashik Riya 7001305949 Independent Escort Service Nashik
Russian Call Girls in Nashik Riya 7001305949 Independent Escort Service NashikRussian Call Girls in Nashik Riya 7001305949 Independent Escort Service Nashik
Russian Call Girls in Nashik Riya 7001305949 Independent Escort Service Nashikranjana rawat
Ā 
(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service
(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service
(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
Ā 
Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...
Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...
Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...Pooja Nehwal
Ā 
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceJp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceHigh Profile Call Girls
Ā 
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
Ā 
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
Ā 
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCyLet Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCystephieert
Ā 
Assessment on SITXINV007 Purchase goods.pdf
Assessment on SITXINV007 Purchase goods.pdfAssessment on SITXINV007 Purchase goods.pdf
Assessment on SITXINV007 Purchase goods.pdfUMER979507
Ā 
VIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130 Available With Room
VIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130  Available With RoomVIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130  Available With Room
VIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130 Available With Roomdivyansh0kumar0
Ā 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1davew9
Ā 
Call Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCe
Call Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCeCall Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCe
Call Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCe9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur EscortsLow Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escortsranjana rawat
Ā 
Call Girl Nashik Khushi 7001305949 Independent Escort Service Nashik
Call Girl Nashik Khushi 7001305949 Independent Escort Service NashikCall Girl Nashik Khushi 7001305949 Independent Escort Service Nashik
Call Girl Nashik Khushi 7001305949 Independent Escort Service Nashikranjana rawat
Ā 

Recently uploaded (20)

BPP NC II Lesson 3 - Pastry Products.pptx
BPP NC II Lesson 3 - Pastry Products.pptxBPP NC II Lesson 3 - Pastry Products.pptx
BPP NC II Lesson 3 - Pastry Products.pptx
Ā 
(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MAYA) Baner Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
Ā 
9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR
9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR
9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR
Ā 
VIP Call Girls In Singar Nagar ( Lucknow ) šŸ” 8923113531 šŸ” Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow  ) šŸ” 8923113531 šŸ”  Cash Payment Avai...VIP Call Girls In Singar Nagar ( Lucknow  ) šŸ” 8923113531 šŸ”  Cash Payment Avai...
VIP Call Girls In Singar Nagar ( Lucknow ) šŸ” 8923113531 šŸ” Cash Payment Avai...
Ā 
NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...
NO1 Trending kala jadu karne wale ka contact number kala jadu karne wale baba...
Ā 
(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(KRITIKA) Balaji Nagar Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
Ā 
(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
(PRIYANKA) Katraj Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune E...
Ā 
Russian Call Girls in Nashik Riya 7001305949 Independent Escort Service Nashik
Russian Call Girls in Nashik Riya 7001305949 Independent Escort Service NashikRussian Call Girls in Nashik Riya 7001305949 Independent Escort Service Nashik
Russian Call Girls in Nashik Riya 7001305949 Independent Escort Service Nashik
Ā 
(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service
(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service
(AARUSHI) Call Girls Shikrapur ( 7001035870 ) HI-Fi Pune Escorts Service
Ā 
Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...
Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...
Ho Sexy Call Girl in Mira Road Bhayandar | ā‚¹,7500 With Free Delivery, Kashimi...
Ā 
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceJp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Ā 
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
(SUNAINA) Call Girls Alandi Road ( 7001035870 ) HI-Fi Pune Escorts Service
Ā 
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
(ISHITA) Call Girls Manchar ( 7001035870 ) HI-Fi Pune Escorts Service
Ā 
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCyLet Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Let Me Relax Dubai Russian Call girls O56338O268 Dubai Call girls AgenCy
Ā 
Assessment on SITXINV007 Purchase goods.pdf
Assessment on SITXINV007 Purchase goods.pdfAssessment on SITXINV007 Purchase goods.pdf
Assessment on SITXINV007 Purchase goods.pdf
Ā 
VIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130 Available With Room
VIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130  Available With RoomVIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130  Available With Room
VIP Kolkata Call Girl Jadavpur šŸ‘‰ 8250192130 Available With Room
Ā 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1
Ā 
Call Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCe
Call Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCeCall Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCe
Call Girls In Ramesh Nagarź§ā¤ šŸ” 9953056974šŸ”ā¤ź§‚ Escort ServiCe
Ā 
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur EscortsLow Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Low Rate Call Girls Nagpur Esha Call 7001035870 Meet With Nagpur Escorts
Ā 
Call Girl Nashik Khushi 7001305949 Independent Escort Service Nashik
Call Girl Nashik Khushi 7001305949 Independent Escort Service NashikCall Girl Nashik Khushi 7001305949 Independent Escort Service Nashik
Call Girl Nashik Khushi 7001305949 Independent Escort Service Nashik
Ā 

Database Akjljljlkjlkjkljlkjldiministration.pptx

  • 1. BAIS Lab Class Module Title: - Use Basic Structured Query Language Module code: BAIS 3062 4/8/2024 Prepared by Instructor Mr.Elias P 1
  • 2. Introduction to SQL ā€¢ What is SQL? ā€¢ SQL stands for Structured Query Language ā€¢ SQL lets you access and manipulate databases ā€¢ SQL is an ANSI (American National Standards Institute) standard ā€¢ SQL stands for Structured Query Language. ā€¢ SQL is a standard language for accessing and manipulating databases. ā€¢ SQL is a widely used database language, providing means of data manipulation (store, retrieve, update, delete) and database creation. 4/8/2024 Prepared by Instructor Mr.Elias P 2
  • 3. Function of SQL ā€¢ What Can SQL do? ā€¢ SQL can execute queries against a database ā€¢ SQL can retrieve data from a database ā€¢ SQL can insert records in a database ā€¢ SQL can update records in a database ā€¢ SQL can delete records from a database ā€¢ SQL can create new databases ā€¢ SQL can create new tables in a database ā€¢ SQL can create stored procedures in a database ā€¢ SQL can create views in a database ā€¢ SQL can set permissions on tables, procedures, and views ā€¢ However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner. ā€¢ provides a fixed set of data types in particular for strings of different length char(n), varchar(n), longvarchar(n) 4/8/2024 Prepared by Instructor Mr.Elias P 3
  • 4. SQL Commands ļ‚§ The standard SQL commands to interact with relational databases are CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These commands can be classified into groups based on their nature: ļ‚§ DDL - Data Definition Language: which defines the structure of the data ļ‚§ DML - Data Manipulation Language: which retrieves or modifies data ļ‚§ DCL - Data Control Language: which defines the privileges granted to database users. ļ‚§ DQL - Data Query Language: Retrieves certain records from one or more tables ļ¶ DDL - Data Definition Language: Command Description CREATE Creates a new table, a view of a table, or other object in database ALTER Modifies an existing database object, such as a table. DROP Deletes an entire table, a view of a table or other object in the database. 4/8/2024 Prepared by Instructor Mr.Elias P 4
  • 5. ļ¶DML - Data Manipulation Language: ļƒ˜ Command Description ā€¢ INSERT Creates a record ā€¢ UPDATE Modifies records ā€¢ DELETE Deletes records ļ¶ DCL - Data Control Language: ļ‚§ Command Description ļ‚§ GRANT Gives a privilege to user ļ‚§ REVOKE Takes back privileges granted from user ļ¶ DQL - Data Query Language: ļ‚§ Command Description ļ‚§ SELECT Retrieves certain records from one or more tables 4/8/2024 Prepared by Instructor Mr.Elias P 5
  • 6. ļƒ˜What is table? ā€¢ The data in RDBMS is stored in database objects called tables. The table is a collection of related data entries and it consists of columns and rows. ā€¢ Remember, a table is the most common and simplest form of data storage in a relational database. Following is the example of a CUSTOMERS table ā€¢ +----+----------+-----+-----------+----------+ ā€¢ | ID | NAME | AGE | ADDRESS | SALARY | ā€¢ +----+----------+-----+-----------+----------+ ā€¢ | 1 | Ramesh | 32 | Ahmadabad | 2000.00 | ā€¢ | 2 | Khilan | 25 | Delhi | 1500.00 | ā€¢ | 3 | kaushik | 23 | Kota | 2000.00 | ā€¢ | 4 | Chaitali | 25 | Mumbai | 6500.00 | ā€¢ | 5 | Hardik | 27 | Bhopal | 8500.00 | ā€¢ | 6 | Komal | 22 | MP | 4500.00 | ā€¢ | 7 | Muffy | 24 | Indore | 10000.00 | ā€¢ +----+----------+-----+-----------+----------+ 4/8/2024 Prepared by Instructor Mr.Elias P 6
  • 7. ļƒ˜What is field? ā€¢ Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS table consist of ID, NAME, AGE, ADDRESS and SALARY. ā€¢ A field is a column in a table that is designed to maintain specific information about every record in the table. ļƒ˜ What is record or row? ā€¢ A record, also called a row of data, is each individual entry that exists in a table. For example, there are 7 records in the above CUSTOMERS table. Following is a single row of data or record in the CUSTOMERS table: ā€¢ +----+----------+-----+-----------+----------+ ā€¢ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | ā€¢ +----+----------+-----+-----------+----------+ ļ¶ A record is a horizontal entity in a table. 4/8/2024 Prepared by Instructor Mr.Elias P 7
  • 8. ļƒ˜What is column? ā€¢ A column is a vertical entity in a table that contains all information associated with a specific field in a table. ā€¢ For example, a column in the CUSTOMERS table is ADDRESS, which represents location description and would consist of the following: +-----------+ | ADDRESS | +-----------+ | Ahmedabad | | Delhi | | Kota | | Mumbai | | Bhopal | | MP | | Indore | +----+------+ 4/8/2024 Prepared by Instructor Mr.Elias P 8
  • 9. What is NULL value? ā€¢ A NULL value in a table is a value in a field that appears to be blank, which means a field with a NULL value is a field with no value. ā€¢ It is very important to understand that a NULL value is different than a zero value or a field that contains spaces. ā€¢ A field with a NULL value is one that has been left blank during record creation. 4/8/2024 Prepared by Instructor Mr.Elias P 9
  • 10. SQL Constraints: ā€¢ Constraints: are the rules enforced on data columns on table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database. ā€¢ Constraints could be column level or table level. Column level constraints are applied only to one column, whereas table level constraints are applied to the whole table. ļ¶ Following are commonly used constraints available in SQL: ā€¢ NOT NULL Constraint: Ensures that a column cannot have NULL value. ā€¢ DEFAULT Constraint: Provides a default value for a column when none is specified. ā€¢ PRIMARY Key: Uniquely identified each rows/records in a database table. ā€¢ FOREIGN Key: Uniquely identified a rows/records in any another database table. ā€¢ UNIQUE Constraint: Ensures that all values in a column are different. ā€¢ CHECK Constraint: The CHECK constraint ensures that all values in a column satisfy certain conditions. ā€¢ INDEX: Use to create and retrieve data from the database very quickly. 4/8/2024 Prepared by Instructor Mr.Elias P 10
  • 11. Data Integrity: ļ¶ The following categories of the data integrity exist with each RDBMS: ā€¢ Entity Integrity : There are no duplicate rows in a table. ā€¢ Domain Integrity : Enforces valid entries for a given column by restricting the type, the format, or the range of values. ā€¢ Referential Integrity : Rows cannot be deleted which are used by other records. ā€¢ User-Defined Integrity : Enforces some specific business rules that do not fall into entity, domain, or referential integrity. 4/8/2024 Prepared by Instructor Mr.Elias P 11
  • 12. SQL Syntax ā€¢ SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a quick start with SQL by listing all the basic SQL Syntax: ā€¢ All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;). ā€¢ Important point to be noted is that SQL is case insensitive, which means SELECT and select have same meaning in SQL statements, but My SQL makes difference in table names. So if you are working with My SQL, then you need to give table names as they exist in the database. 4/8/2024 Prepared by Instructor Mr.Elias P 12
  • 13. 1. PRIMARY KEY ā€¢ The PRIMARY KEY:-constraint uniquely identifies each record in a database table. ā€¢ A primary key is a field in a table which uniquely identifies each row/record in a database table. Primary keys must contain unique values. A primary key column cannot have NULL values. ā€¢ A table can have only one primary key, which may consist of single or multiple fields. When multiple fields are used as a primary key, they are called a composite key. ā€¢ If a table has a primary key defined on any field(s), then you can not have two records having the same value of that field(s). ā€¢ Note: You would use these concepts while creating database tables. ā€¢ Create Primary Key: ā€¢ Here is the syntax to define ID attribute as a primary key in a CUSTOMERS table 4/8/2024 Prepared by Instructor Mr.Elias P 13
  • 14. ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL, ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2), ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 14
  • 15. 2. NOT NULL Constraint: ā€¢ By default, a column can hold NULL values. If you do not want a column to have a NULL value, then you need to define such constraint on this column specifying that NULL is now not allowed for that column. ā€¢ A NULL is not the same as no data, rather, it represents unknown data. Example: ā€¢ For example, the following SQL creates a new table called CUSTOMERS and adds five columns, three of which, ID and NAME and AGE, specify not to accept NULLs: 4/8/2024 Prepared by Instructor Mr.Elias P 15
  • 16. Contiā€¦ ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL, ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2), ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 16
  • 17. 3.DEFAULT Constraint: ā€¢ The DEFAULT constraint provides a default value to a column when the INSERT INTO statement does not provide a specific value. ā€¢ Example: For example, the following SQL creates a new table called CUSTOMERS and adds five columns. ā€¢ Here, SALARY column is set to 5000.00 by default, so in case INSERT INTO statement does not provide a value for this column. then by default this column would be set to 5000.00. 4/8/2024 Prepared by Instructor Mr.Elias P 17
  • 18. Contiā€¦. ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL, ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2) DEFAULT 5000.00, ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 18
  • 19. 4.UNIQUE Constraint: ā€¢ The UNIQUE Constraint prevents two records from having identical values in a particular column. ā€¢ In the CUSTOMERS table, for example, you might want to prevent two or more people from having identical age. Example: ā€¢ For example, the following SQL creates a new table called CUSTOMERS and adds five columns. Here, AGE column is set to UNIQUE, so that you can not have two records with same age: 4/8/2024 Prepared by Instructor Mr.Elias P 19
  • 20. Contiā€¦. ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL UNIQUE, ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2), ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 20
  • 21. 5.FOREIGN Key: ā€¢ A foreign key is a key used to link two tables together. ā€¢ This is sometimes called a referencing key. ā€¢ Foreign Key is a column or a combination of columns whose values match a Primary Key in a different table. ā€¢ The relationship between 2 tables matches the Primary Key in one of the tables with a Foreign Key in the second table. ā€¢ If a table has a primary key defined on any field(s), then you can not have two records having the same value of that field(s). Example: ā€¢ Consider the structure of the two tables as follows: 4/8/2024 Prepared by Instructor Mr.Elias P 21
  • 22. CUSTOMERS table: ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL, ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2), ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 22
  • 23. ORDERS table: ā€¢ CREATE TABLE ORDERS ( ā€¢ ID INT NOT NULL, ā€¢ DATE DATETIME, ā€¢ CUSTOMER_ID INT references CUSTOMERS(ID), ā€¢ AMOUNT double, ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 23
  • 24. 6.CHECK Constraint: ā€¢ The CHECK Constraint enables a condition to check the value being entered into a record. ā€¢ If the condition evaluates to false, the record violates the constraint and isnā€™t entered into the table. ā€¢ Example: For example, the following SQL creates a new table called CUSTOMERS and adds five columns. ā€¢ Here, we add a CHECK with AGE column, so that you can not have any CUSTOMER below 18 years: 4/8/2024 Prepared by Instructor Mr.Elias P 24
  • 25. Contiā€¦. ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL CHECK (AGE >= 18), ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2), ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 25
  • 26. 7. INDEX: ā€¢ The INDEX is used to create and retrieve data from the database very quickly. Index can be created by using single or group of columns in a table. ā€¢ When index is created, it is assigned a ROWID for each row before it sorts out the data. ā€¢ Proper indexes are good for performance in large databases, but you need to be careful while creating index. ā€¢ Selection of fields depends on what you are using in your SQL queries. Example: For example, the following SQL creates a new table called CUSTOMERS and adds five columns: 4/8/2024 Prepared by Instructor Mr.Elias P 26
  • 27. Contiā€¦. ā€¢ CREATE TABLE CUSTOMERS( ā€¢ ID INT NOT NULL, ā€¢ NAME VARCHAR (20) NOT NULL, ā€¢ AGE INT NOT NULL, ā€¢ ADDRESS CHAR (25) , ā€¢ SALARY DECIMAL (18, 2), ā€¢ PRIMARY KEY (ID) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 27
  • 28. Contiā€¦ ā€¢ Now, you can create index on single or multiple columns using the following syntax: ā€¢ CREATE INDEX index_name ā€¢ ON table_name ( column1, column2.....); ā€¢ To create an INDEX on AGE column, to optimize the search on customers for a particular age, following is the SQL syntax: ā€¢ CREATE INDEX idx_age ā€¢ ON CUSTOMERS ( AGE ); 4/8/2024 Prepared by Instructor Mr.Elias P 28
  • 29. 1.SQL CREATE Database ā€¢ The SQL CREATE DATABASE statement is used to create new SQL database. ā€¢ Syntax: Basic syntax of CREATE DATABASE statement is as follows: ā€¢ CREATE DATABASE Database Name; ā€¢ Always database name should be unique within the RDBMS. Example: ā€¢ If you want to create new database <testDB>, then CREATE DATABASE statement would be as follows: 4/8/2024 Prepared by Instructor Mr.Elias P 29
  • 30. Conti.. ā€¢ SQL> CREATE DATABASE test DB; ā€¢ Make sure you have admin privilege before creating any database. ā€¢ Once a database is created, you can check it in the list of databases as follows: 4/8/2024 Prepared by Instructor Mr.Elias P 30
  • 31. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 31
  • 32. 2. DROP or DELETE Database ā€¢ The SQL DROP DATABASE statement is used to drop an existing database in SQL schema. ā€¢ Syntax: Basic syntax of DROP DATABASE statement is as follows: ā€¢ DROP DATABASE Data base Name; ā€¢ Always database name should be unique within the RDBMS. ā€¢ Example: If you want to delete an existing database <test DB>, then DROP DATABASE statement would be as follows: ā€¢ SQL> DROP DATABASE test DB; 4/8/2024 Prepared by Instructor Mr.Elias P 32
  • 33. Contiā€¦. ā€¢ NOTE: Be careful before using this operation because by deleting an existing database would result in loss of complete information stored in the database. ā€¢ Make sure you have admin privilege before dropping any database. ā€¢ Once a database is dropped, you can check it. 4/8/2024 Prepared by Instructor Mr.Elias P 33
  • 34. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 34
  • 35. 3.SQL SELECT Database ā€¢ The SELECT statement is probably the most used SQL command. ā€¢ The SELECT statement is used for retrieving rows from the database and enables the selection of one or many rows or columns from one or many tables in the database. 4/8/2024 Prepared by Instructor Mr.Elias P 35
  • 36. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 36
  • 37. EXAMPLE 4/8/2024 Prepared by Instructor Mr.Elias P 37
  • 38. Conti.. 4/8/2024 Prepared by Instructor Mr.Elias P 38
  • 39. 4.SQL CREATE Table ā€¢ Creating a basic table involves naming the table and defining its columns and each column's data type. ā€¢ The SQL CREATE TABLE statement is used to create a new table. ā€¢ Syntax: Basic syntax of CREATE TABLE statement is as follows: 4/8/2024 Prepared by Instructor Mr.Elias P 39
  • 40. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 40
  • 41. 5.SQL DROP or DELETE Table ā€¢ The SQL DROP TABLE statement is used to remove a table definition and all data, indexes, triggers, constraints, and permission specifications for that table. ā€¢ NOTE: You have to be careful while using this command because once a table is deleted then all the information available in the table would also be lost forever. ā€¢ Syntax: Basic syntax of DROP TABLE statement is as follows: ā€¢ DROP TABLE table_name; ā€¢ SQL> DROP TABLE CUSTOMERS; Query OK, 0 rows affected (0.01 sec) 4/8/2024 Prepared by Instructor Mr.Elias P 41
  • 42. 6. SQL INSERT Query ā€¢ The SQL INSERT INTO Statement is used to add new rows of data to a table in the database. ā€¢ Syntax: There are two basic syntaxes of INSERT INTO statement as follows: ā€¢ INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)] ā€¢ VALUES (value1, value2, value3,...valueN); 4/8/2024 Prepared by Instructor Mr.Elias P 42
  • 43. Contiā€¦ ā€¢ Here, column1, column2,...columnN are the names of the columns in the table into which you want to insert data. ā€¢ You may not need to specify the column(s) name in the SQL query if you are adding values for all the columns of the table. ā€¢ But make sure the order of the values is in the same order as the columns in the table. ā€¢ The SQL INSERT INTO syntax would be as follows: ā€¢ INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN); 4/8/2024 Prepared by Instructor Mr.Elias P 43
  • 44. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 44
  • 45. ā€¢ You can create a record in CUSTOMERS table using second syntax as follows: ā€¢ INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24, 'Indore', 10000.00 ); 4/8/2024 Prepared by Instructor Mr.Elias P 45
  • 46. Contiā€¦.. 4/8/2024 Prepared by Instructor Mr.Elias P 46
  • 47. 7. SQL SELECT Query ā€¢ SQL SELECT Statement is used to fetch the data from a database table which returns data in the form of result table. ā€¢ These result tables are called result-sets. ā€¢ Syntax: The basic syntax of SELECT statement is as follows: ā€¢ SELECT column1, column2, columnN FROM table_name; ā€¢ Here, column1, column2...are the fields of a table whose values you want to fetch. ā€¢ If you want to fetch all the fields available in the field, then you can use the following syntax: ā€¢ SELECT * FROM table_name; 4/8/2024 Prepared by Instructor Mr.Elias P 47
  • 48. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 48
  • 49. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 49
  • 50. 8. SQL WHERE Clause ā€¢ The SQL WHERE clause is used to specify a condition while fetching the data from single table or joining with multiple tables. If the given condition is satisfied, then only it returns specific value from the table. You would use WHERE clause to filter the records and fetching only necessary records. The WHERE clause is not only used in SELECT statement, but it is also used in UPDATE, DELETE statement, etc., which we would examine in subsequent chapters. Syntax: The basic syntax of SELECT statement with WHERE clause is as follows: SELECT column1, column2, columnN FROM table_name WHERE [condition] You can specify a condition using comparison or logical operators like >, <, =, LIKE, NOT etc. Below examples would make this concept clear. 4/8/2024 Prepared by Instructor Mr.Elias P 50
  • 51. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 51
  • 52. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 52
  • 53. 9. SQL AND And OR Operators ā€¢ The SQL AND and OR operators are used to combine multiple conditions to narrow data in an SQL statement. ā€¢ These two operators are called conjunctive operators. These operators provide a means to make multiple comparisons with different operators in the same SQL statement. The AND Operator: The AND operator allows the existence of multiple conditions in an SQL statement's WHERE clause. Syntax: The basic syntax of AND operator with WHERE clause is as follows: SELECT column1, column2, columnN FROM table_name WHERE [condition1] AND [condition2]...AND [conditionN]; You can combine N number of conditions using AND operator. For an action to be taken by the SQL statement, whether it be a transaction or query, all conditions separated by the AND must be TRUE. 4/8/2024 Prepared by Instructor Mr.Elias P 53
  • 54. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 54
  • 55. Contiā€¦.. 4/8/2024 Prepared by Instructor Mr.Elias P 55
  • 56. The OR Operator: ā€¢ The OR operator is used to combine multiple conditions in an SQL statement's WHERE clause. Syntax: The basic syntax of OR operator with WHERE clause is as follows: SELECT column1, column2, columnN FROM table_name WHERE [condition1] OR [condition2]...OR [conditionN] You can combine N number of conditions using OR operator. For an action to be taken by the SQL statement, whether it be a transaction or query, only any ONE of the conditions separated by the OR must be TRUE. 4/8/2024 Prepared by Instructor Mr.Elias P 56
  • 57. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 57
  • 58. 10.SQL UPDATE Query ā€¢ The SQL UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows, otherwise all the rows would be affected. Syntax: The basic syntax of UPDATE query with WHERE clause is as follows: UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition]; You can combine N number of conditions using AND or OR operators. 4/8/2024 Prepared by Instructor Mr.Elias P 58
  • 59. Example 4/8/2024 Prepared by Instructor Mr.Elias P 59
  • 60. Contiā€¦ā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 60
  • 61. 11. ALTER TABLE ā€¢ The ALTER TABLE statement is used to add, delete, or modify columns in an existing table. ā€¢ To add a column in a table, use the following syntax: ALTER TABLE table_name ADD column_name datatype ā€¢ To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column): ā€¢ ALTER TABLE table_name DROP COLUMN column_name ā€¢ To change the data type of a column in a table, use the following syntax: ALTER TABLE table_name ALTER COLUMN column_name datatype 4/8/2024 Prepared by Instructor Mr.Elias P 61
  • 62. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 62
  • 63. Contiā€¦.. 4/8/2024 Prepared by Instructor Mr.Elias P 63
  • 64. 12. SQL TRUNCATE TABLE ā€¢ The SQL TRUNCATE TABLE command is used to delete complete data from an existing table. ā€¢ You can also use DROP TABLE command to delete complete table but it would remove complete table structure form the database and you would need to re- create this table once again if you wish you store some data. Syntax: The basic syntax of TRUNCATE TABLE is as follows: TRUNCATE TABLE table_name; 4/8/2024 Prepared by Instructor Mr.Elias P 64
  • 65. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 65
  • 66. 13. SQL DELETE Query ā€¢ The SQL DELETE Query is used to delete the existing records from a table. ā€¢ You can use WHERE clause with DELETE query to delete selected rows, otherwise all the records would be deleted. Syntax: ā€¢ The basic syntax of DELETE query with WHERE clause is as follows: ā€¢ DELETE FROM table_name WHERE [condition]; ā€¢ You can combine N number of conditions using AND or OR operators. 4/8/2024 Prepared by Instructor Mr.Elias P 66
  • 67. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 67
  • 68. Contiā€¦ā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 68
  • 69. 14. SQL LIKE Clause ā€¢ The SQL LIKE clause is used to compare a value to similar values using wildcard operators. ā€¢ There are two wildcards used in conjunction with the LIKE operator: The percent sign (%) The underscore (_) The percent sign represents zero, one, or multiple characters. ā€¢ The underscore represents a single number or character. ā€¢ The symbols can be used in combinations. 4/8/2024 Prepared by Instructor Mr.Elias P 69
  • 70. Syntax: ā€¢ The basic syntax of % and _ is as follows: SELECT FROM table_name WHERE column LIKE 'XXXX%' or SELECT FROM table_name WHERE column LIKE '%XXXX%' or SELECT FROM table_name WHERE column LIKE 'XXXX_' or SELECT FROM table_name WHERE column LIKE '_XXXX' or SELECT FROM table_name WHERE column LIKE '_XXXX_ā€˜ ā€¢ You can combine N number of conditions using AND or OR operators. Here, XXXX could be any numeric or string value. 4/8/2024 Prepared by Instructor Mr.Elias P 70
  • 71. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 71
  • 72. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 72
  • 73. Example 4/8/2024 Prepared by Instructor Mr.Elias P 73
  • 74. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 74
  • 75. 15. SQL TOP Clause ā€¢ The SQL TOP clause is used to fetch a TOP N number or X percent records from a table. Note: All the databases do not support TOP clause. For example MySQL supports LIMIT clause to fetch limited number of records and Oracle uses ROWNUM to fetch limited number of records. Syntax: The basic syntax of TOP clause with SELECT statement would be as follows: SELECT TOP number|percent column_name(s) FROM table_name WHERE [condition] 4/8/2024 Prepared by Instructor Mr.Elias P 75
  • 76. Example 4/8/2024 Prepared by Instructor Mr.Elias P 76
  • 77. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 77
  • 78. 16. SQL ORDER BY Clause ā€¢ The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. Some database sorts query results in ascending order by default. Syntax: The basic syntax of ORDER BY clause is as follows: SELECT column-list FROM table_name [WHERE condition] [ORDER BY column1, column2, .. columnN] [ASC | DESC]; You can use more than one column in the ORDER BY clause. ā€¢ Make sure whatever column you are using to sort, that column should be in column-list. 4/8/2024 Prepared by Instructor Mr.Elias P 78
  • 79. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 79
  • 80. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 80
  • 81. 17. SQL Distinct Keyword ā€¢ The SQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the duplicate records and fetching only unique records. There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only unique records instead of fetching duplicate records. Syntax: The basic syntax of DISTINCT keyword to eliminate duplicate records is as follows: SELECT DISTINCT column1, column2,.....columnN FROM table_name WHERE [condition] 4/8/2024 Prepared by Instructor Mr.Elias P 81
  • 82. Example: 4/8/2024 Prepared by Instructor Mr.Elias P 82
  • 83. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 83
  • 84. 18. SQL Joins ā€¢ The SQL Joins clause is used to combine records from two or more tables in a database. ā€¢ A JOIN is a means for combining fields from two tables by using values common to each. 4/8/2024 Prepared by Instructor Mr.Elias P 84
  • 85. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 85
  • 86. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 86
  • 87. SQL Join Types: ā€¢ There are different types of joins available in SQL: ā€¢ INNER JOIN: returns rows when there is a match in both tables. ā€¢ LEFT JOIN: returns all rows from the left table, even if there are no matches in the right table. ā€¢ RIGHT JOIN: returns all rows from the right table, even if there are no matches in the left table. ā€¢ FULL JOIN: returns rows when there is a match in one of the tables. 4/8/2024 Prepared by Instructor Mr.Elias P 87
  • 88. INNER JOIN ā€¢ The most frequently used and important of the joins is the INNER JOIN. ā€¢ They are also referred to as an EQUIJOIN. ā€¢ The INNER JOIN creates a new result table by combining column values of two tables (table1 and table2) based upon the join-predicate. ā€¢ The query compares each row of table1 with each row of table2 to find all pairs of rows which satisfy the join- predicate. ā€¢ When the join-predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row. 4/8/2024 Prepared by Instructor Mr.Elias P 88
  • 89. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 89
  • 90. (b) Another table is ORDERS as follows: 4/8/2024 Prepared by Instructor Mr.Elias P 90
  • 91. LEFT JOIN ā€¢ The SQL LEFT JOIN returns all rows from the left table, even if there are no matches in the right table. ā€¢ This means that if the ON clause matches 0 (zero) records in right table, the join will still return a row in the result, but with NULL in each column from right table. ā€¢ This means that a left join returns all the values from the left table, plus matched values from the right table or NULL in case of no matching join predicate. 4/8/2024 Prepared by Instructor Mr.Elias P 91
  • 92. Contiā€¦.. 4/8/2024 Prepared by Instructor Mr.Elias P 92
  • 93. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 93
  • 94. Contiā€¦.. 4/8/2024 Prepared by Instructor Mr.Elias P 94
  • 95. RIGHT JOIN ā€¢ The SQL RIGHT JOIN returns all rows from the right table, even if there are no matches in the left table. ā€¢ This means that if the ON clause matches 0 (zero) records in left table, the join will still return a row in the result, but with NULL in each column from left table. ā€¢ This means that a right join returns all the values from the right table, plus matched values from the left table or NULL in case of no matching join predicate. 4/8/2024 Prepared by Instructor Mr.Elias P 95
  • 96. Contiā€¦. ā€¢ Syntax: The basic syntax of RIGHT JOIN is as follows: ā€¢ SELECT table1.column1, table2.column2... FROM table1 RIGHT JOIN table2 ON table1.common_filed = table2.common_field; ā€¢ Example: Consider the following two tables, (a) CUSTOMERS table is as follows: 4/8/2024 Prepared by Instructor Mr.Elias P 96
  • 97. Contiā€¦. 4/8/2024 Prepared by Instructor Mr.Elias P 97
  • 98. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 98
  • 99. FULL JOIN ā€¢ The SQL FULL JOIN combines the results of both left and right outer joins. ā€¢ The joined table will contain all records from both tables, and fill in NULLs for missing matches on either side. ā€¢ Syntax: ā€¢ The basic syntax of FULL JOIN is as follows: ā€¢ SELECT table1.column1, table2.column2... FROM table1 FULL JOIN table2 ON table1.common_filed = table2.common_field; ā€¢ Here given condition could be any given expression based on your requirement. 4/8/2024 Prepared by Instructor Mr.Elias P 99
  • 100. example 4/8/2024 Prepared by Instructor Mr.Elias P 100
  • 101. Contiā€¦ 4/8/2024 Prepared by Instructor Mr.Elias P 101
  • 102. Contiā€¦ā€¦. ā€¢ If your Database does not support FULL JOIN like MySQL does not support FULL JOIN, then you can use UNION ALL clause to combine two JOINS as follows: ā€¢ SQL> SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS LEFT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID UNION ALL SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS RIGHT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID 4/8/2024 Prepared by Instructor Mr.Elias P 102
  • 103. SQL Syntax ā€¢ SQL is followed by unique set of rules and guidelines called Syntax. This tutorial gives you a quick start with SQL by listing all the basic SQL Syntax: ā€¢ All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;). ā€¢ Important point to be noted is that SQL is case insensitive, which means SELECT and select have same meaning in SQL statements, but MySQL makes difference in table names. So if you are working with MySQL, then you need to give table names as they exist in the database. 4/8/2024 Prepared by Instructor Mr.Elias P 103
  • 104. 1. SQL SELECT Statement: ā€¢ SELECT column1, column2....columnN FROM table_name; ā€¢ 2. SQL INSERT INTO Statement: ā€¢ INSERT INTO table_name( column1, column2....columnN) VALUES ( value1, value2....valueN); ā€¢ 3. SQL UPDATE Statement: ā€¢ UPDATE table_name SET column1 = value1, column2 = value2....columnN=valueN [ WHERE CONDITION ]; 4/8/2024 Prepared by Instructor Mr.Elias P 104
  • 105. 4. SQL DELETE Statement: ā€¢ DELETE FROM table_name WHERE {CONDITION}; ā€¢ 5. SQL CREATE DATABASE Statement: ā€¢ CREATE DATABASE database_name; ā€¢ 6. SQL DROP DATABASE Statement: ā€¢ DROP DATABASE database_name; ā€¢ 7. SQL USE Statement: ā€¢ USE DATABASE database_name; 4/8/2024 Prepared by Instructor Mr.Elias P 105
  • 106. 8. SQL INSERT INTO Statement: ā€¢ INSERT INTO table_name( column1, column2....columnN) VALUES ( value1, value2....valueN); ā€¢ 9. SQL ALTER TABLE Statement (Rename): ā€¢ ALTER TABLE table_name RENAME TO new_table_name; ā€¢ 10. SQL ALTER TABLE Statement: ā€¢ ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype}; 4/8/2024 Prepared by Instructor Mr.Elias P 106
  • 107. 11. SQL TRUNCATE TABLE Statement: ā€¢ TRUNCATE TABLE table_name; ā€¢ 12. SQL CREATE TABLE Statement: ā€¢ CREATE TABLE table_name( ā€¢ column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) ā€¢ ); 4/8/2024 Prepared by Instructor Mr.Elias P 107
  • 108. 13. SQL COUNT Clause: ā€¢ SELECT COUNT(column_name) FROM table_name WHERE CONDITION; ā€¢ 14. SQL ORDER BY Clause: ā€¢ SELECT column1, column2....columnN FROM table_name WHERE CONDITION ORDER BY column_name {ASC|DESC}; ā€¢ 15. SQL LIKE Clause: ā€¢ SELECT column1, column2....columnN FROM table_name WHERE column_name LIKE { PATTERN }; 4/8/2024 Prepared by Instructor Mr.Elias P 108
  • 109. 16. SQL BETWEEN Clause: ā€¢ SELECT column1, column2....columnN FROM table_name WHERE column_name BETWEEN val-1 AND val-2; ā€¢ 17. SQL AND/OR Clause: ā€¢ SELECT column1, column2....columnN FROM table_name WHERE CONDITION-1 {AND|OR} CONDITION-2; 4/8/2024 Prepared by Instructor Mr.Elias P 109
  • 110. 18. SQL DISTINCT Clause: ā€¢ SELECT DISTINCT column1, column2....columnN FROM table_name; ā€¢ 19. SQL WHERE Clause: ā€¢ SELECT column1, column2....columnN FROM table_name WHERE CONDITION; 4/8/2024 Prepared by Instructor Mr.Elias P 110
  • 111. ā€¢THE END !!! ā€¢THANK YOU . ā€¢IF YOU HAVE ANY QUESTION WELL COME!! 4/8/2024 Prepared by Instructor Mr.Elias P 111