Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Structured Query Language (SQL).pptx
1. 1
Structured Query Language (SQL)
What is SQL?
Is a language of database, it includes database creation,
deletion, fetching rows and modifying rows etc.
SQL is Structured Query Language, which is a computer
language for storing, manipulating and retrieving data stored in
relational database.
2. 2
Why SQL?
• Allows users to access data in relational database management
systems.
• Allows users to describe the data.
• Allows users to define the data in database and manipulate that data.
• Allows users to create and drop databases and tables.
• Allows users to create view, stored procedure, functions in a database.
• Allows users to set permissions on tables, procedures and views
3. 3
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 (;).
4. 4
SQL Syntax
• 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.
5. 5
SQL Statements
Most of the actions you need to perform on a database are done with SQL
statements.
Semicolon after SQL Statements?
Some database systems require a semicolon at the end of each SQL
statement. Semicolon is the standard way to separate each SQL statement
in database systems that allow more than one SQL statement to be
executed in the same call to the server.
6. 6
SQL DML and DDL
SQL can be divided into two parts: The Data Manipulation
Language (DML) and the Data Definition Language (DDL).
7. 7
DDL - Data Definition Language:
The DDL part of SQL permits database tables to be created or
deleted. It also defines indexes (keys), specifies links between
tables, and imposes constraints between tables. The most
important DDL statements in SQL are:
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
8. 8
DDL - Data Definition Language:
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
9. 9
DML - Data Manipulation Language:
The query and update commands form the DML part of SQL:
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
10. 10
1. SQL SELECT Statement
The SELECT statement is used to select data from a database. The result
is stored in a result table, called the result-set.
SQL SELECT Syntax:
SELECT column_name(s)
FROM table_name
And
SELECT * FROM table_name
Note: SQL is not case sensitive. SELECT is the same as select.
11. 11
Example: SELECT
Table Name: Students
StudentsID LastName FirstName Address City
1 Cabuso Fernan San Pedro Puerto Princesa
2 Porras Ellen Grace Alfonso XIII Quezon
3 Dela Cruz Steven Tabon Quezon
Now we want to select the content of the columns named "LastName" and
"FirstName" from the table above.
We use the following SELECT statement:
SELECT LastName, FirstName
FROM Students
12. 12
Example: SELECT
Table Name: Students
The result-set will look like this:
LastName FirstName
Cabuso Fernan
Porras Ellen Grace
Dela Cruz Steven
13. 13
Example: SELECT
Table Name: Students
Now we want to select all the columns from the “Students"
table. We use the following SELECT statement:
SELECT *
FROM Students
Or
SELECT * FROM Students
Tip: The asterisk (*) is a quick way of selecting all columns!
14. 14
Example: SELECT
Table Name: Students
The result-set will look like this:
StudentsID LastName FirstName Address City
1 Cabuso Fernan San Pedro Puerto Princesa
2 Porras Ellen Grace Alfonso XIII Quezon
3 Dela Cruz Steven Tabon Quezon
15. 15
2. SQL SELECT DISTINCT Statement
In a table, some of the columns may contain duplicate values. This is
not a problem, however, sometimes you will want to list only the
different (distinct) values in a table.
The DISTINCT keyword can be used to return only distinct (different)
values.
SQL SELECT DISTINCT Syntax:
SELECT DISTINCT column_name(s)
FROM table_name
16. 16
Example: SELECT DISTINCT
Table Name: Students
Now we want to select only the distinct values from the column
named "City" from the table above.
StudentsID LastName FirstName Address City
1 Cabuso Fernan San Pedro Puerto Princesa
2 Porras Ellen Grace Alfonso XIII Quezon
3 Dela Cruz Steven Tabon Quezon
17. 17
Example: SELECT DISTINCT
Table Name: Students
We use the following SELECT statement:
SELECT DISTINCT City FROM Students
The result-set will look like this:
City
Puerto Princesa
Quezon