Erbil polytechnic university
Erbil technology college
ICTE
SQL
Prepared by Supervisor
Azheen Taher Abdullah MR. Ferman I. Kareem
Group: A 1
2024-2023
1
Contents
Introduction to SQL.….…………………………………..…………..……………………………………………………..1
What Can SQL do?…………………………….…………………………………………………………….………………...2
How SQL Work? ………………………………………………….…………………………………………………………..…3
Some of The Most Important SQL Commands……..............................................................4
SQL Statements………………………………………………………………………………………………………………….4
1-The SQL SELECT Statement.………………………………………………………………………………………….4
The SQL SELECT DISTINCT Statement…….……………………………………………………………………..5
2-The SQL UPDATE Statement….………………………………………..…………………………..……..………..5
3- SQL - DELETE ……………………..……………………………………………..………………………………………….5
4-The SQL INSERT INTO Statement………………………………………..………..…….……………………...6
5- SQL - CREATE Table …..………………………………………….….…………...……………………….……….….6
6-The SQL WHERE....................................................................................................................7
7-The SQL DROP TABLE Statement………………..………….........................................................7
References.................................................................................................................................8
2
Introduction to SQL
SQL is a standard language for accessing and manipulating databases.
What is SQL?
SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate
with a database. According to ANSI (American National Standards Institute), it is the standard
language for relational database management systems. • SQL (Structured Query Language) is a
programming language used for manipulating and managing data in relational databases such as
Microsoft Access, MySQL. Although SQL is an ANSI standard, there are different versions of the SQL
language. 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
• SQL stands for Structured Query Language
• SQL lets you access and manipulate databases
• SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of
the International Organization for Standardization (ISO) in 1987
1
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
2
How SQL Work?
• When a user wants to get some information from a database file, he can issue a query.
• A query is a user–request to retrieve data or information with a certain condition.
• The user specifies a certain condition.
• The program will go through all the records in the database file and select those records that
satisfy the condition. (searching).
• The result of the query will then be stored in form of a table.
3
Some of The Most Important SQL Commands
• 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
• CREATE TABLE - creates a new table
• Where clause - WHERE clause is used to filter records.
• DROP TABLE - deletes a table
SQL Statements
Most of the actions you need to perform on a database are done with SQL statements.
SQL statements consists of keywords that are easy to understand.
The following SQL statement returns all records from a table named "Customers":
1-The SQL SELECT Statement
The SELECT statement is used to select data from a database.
Syntax
SELECT column1, column2, ...
FROM table_name;
Here, column1, column2, ... are the field names of the table you want to select data from.
The table name represents the name of the table you want to select data from.
ExampleGet your own SQL Server
Return data from the Customers table:
SELECT Customer Name, City FROM Customers;
4
The SQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values.
Syntax
SELECT DISTINCT column1, column2, ...
FROM table name;
ExampleGet your own SQL Server
Select all the different countries from the "Customers" table:
SELECT DISTINCT Country FROM Customers;
2-The SQL UPDATE Statement
The UPDATE statement is used to modify the existing records in a table.
UPDATE Syntax
UPDATE table name
SET column1 = value1, column2 = value2, ...
WHERE condition;
3- SQL - DELETE
The DELETE statement is used to delete existing records in a table.
DELETE Syntax
DELETE FROM table name WHERE condition;
SQL DELETE Example
The following SQL statement deletes the customer "Alfreds Futterkiste" from the "Customers" table:
Example Get your own SQL Server
DELETE FROM Customers WHERE Customer Name='Alfreds Futterkiste';
5
4- The SQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.
INSERT INTO Syntax
It is possible to write the INSERT INTO statement in two ways:
1. Specify both the column names and the values to be inserted:
INSERT INTO table name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
2. If you are adding values for all the columns of the table, you do not need to specify the column
names in the SQL query. However, make sure the order of the values is in the same order as the
columns in the table. Here, the INSERT INTO syntax would be as follows:
INSERT INTO table name
VALUES (value1, value2, value3, ...);
5- 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. CREATE TABLE table _name(
column1 datatype, column2 datatype, column3 datatype, ..... column N datatype, PRIMARY
KEY(NAME of pk ) );
• The column parameters specify the names of the columns of the table.
• The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date,
etc.).
6
6- The SQL WHERE
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Example Get your own SQL Server
Select all customers from Mexico:
SELECT * FROM Customers
WHERE Country='Mexico';
7-The SQL DROP TABLE Statement
The DROP TABLE statement is used to drop an existing table in a database.
Syntax DROP TABLE table _name;
7
References
[Link]
[Link]