SQL is a standard language used to communicate with databases to perform tasks like storing, manipulating, and retrieving data. It includes commands like SELECT, INSERT, UPDATE, and DELETE. The SELECT statement is used to retrieve data from database tables. It can select all columns using "*" or specific columns by name. The WHERE clause filters records by specifying conditions that must be true. Operators like AND and OR can be used to filter records based on multiple conditions.
2. Topics:
• What is SQL?
• SQL Commands
• SQL Select Statement
•SQLچیست؟
•دستوراتSQL
•دستورSelect،SQL
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
2
3. What is SQL?
• SQL is Structured Query
Language, which is a
computer language for
storing, manipulating and
retrieving data stored in
relational database.
• SQL is an ANSI (American
National Standards
Institute) standard but
there are many different
versions of the SQL
language.
•SQLمخفف که(Structured
Query Language)عبارت است
ذخی برای کمپیوتر زبان یک ازره
بازیاف و کردن دستکاری ،کردنتن
راب دیتابیس در شده ذخیره دیتاطه
میباشد ای.
•SQLشده قبول معیاری زبان یک
توسط(ANSI)نسخه دارای اما بوده
میباشد مختلف های.
Nangarhar University Database1 3
4. Continue…
• SQL is the standard
language for Relation
Database System. All
relational database
management systems like
MySQL, MS Access, Oracle,
Sybase, Informix, Postgres
and SQL Server use SQL as
standard database
language.
•SQLسیست برای معیار زبان یکم
میباشد ای رابطه دیتابیس.تمام
RDBMSمانند هاMySQL،MS
Access،Oracle،Sybase،
Informix،PostgresوSQL
Serverزبان ازSQLیک منحیث
می استفاده دیتابیس معیار زبانکند.
Nangarhar University Database1 4
5. SQL commands:
• SQL commands are
instructions, coded into SQL
statements, which are used
to communicate with the
database to perform
specific tasks, work,
functions and queries with
data.
• These commands can be
classified into four groups:
•دستوراتSQLدستورات از عبارت
با کردن مکالمه برای که میباشد
وظ یک تا میرود بکار دیتابیسیفه
شود اجرا خاص.
•تقس بخش چهار به دستورات اینیم
میتواند شده:
.1DDL
.2DML
.3DCL
.4TCL
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
5
6. 1) DDL:
• DDL is abbreviation of Data
Definition Language. It is
used to create and modify
the structure of database
objects in database. The
commands are CREATE,
ALTER, DROP, RENAME, and
TRUNCATE.
•DDLاختصارData Definition
Languageمیباشد.برای که
ساختار کردن اصالح و ساختن
ب دیتابیس در دیتابیس اشیایکار
میرود.
•مثال بطور:
•Create،Alter،Drop،
RenameوTruncate
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
6
7. 2) DML:
• DML is abbreviation of Data
Manipulation Language. It
is used to retrieve, store,
modify, delete, insert and
update data in database.
These Data Manipulation
Language commands
are: SELECT, INSERT, UPDAT
E, and DELETE.
•DMLاختصارData
Manipulation Language
میباشد.ذخی ،بازیافتن برای کهره
،کردن حذف ،کردن اصالح ،کردن
دیتا درآوردن روز به و کردن درج
میرود بکار دیتابیس در.
•مثال بطور:
•Select،Insert،Updateو
Delete
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
7
8. 3) DCL:
• DCL is abbreviation of Data
Control Language. It is used
to create roles, permissions,
and referential integrity as
well it is used to control
access to database by
securing it. These
commands are GRANT and
REVOKE.
•DCLاختصارData Control
Languageمیباشد.برای که
جامعیتی و اجازه ،اصول ساختن
کنترول برای همچنان ارجاعی
منظور به دیتابیس به دسترسیامن
میرود بکار آن ساختن.
•مثال بطور:
•GrantوRevoke
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
8
9. 4) TCL:
• TCL is abbreviation
of Transactional Control
Language. It is used to
manage different
transactions occurring
within a database. These
commands are COMMIT,
ROLLBACK, and SAVEPOINT.
•TCLاختصارTransactional
Control Languageمیباشد.که
های تراکنش کردن اداره برای
اتفاق دیتابیس در ایکه مختلفمی
میرود بکار افتد.
•مثال بطور:
•Commit،Rollbackو
Savepoint
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
9
10. SQL Select Statement:
• The SELECT statement is
used to select data from a
table.
• Syntax:
• SELECT column_name(s)
FROM table_name.
• Note: SQL statements are
not case sensitive. SELECT is
the same as select.
•دستورselectکردن انتخاب برای
میرود بکار جدول یک از دیتا.
•است ذیل قرار آن ساختار:
• SELECT column_name(s)
FROM table_name.
•نوت:دستوراتSQLمیتوانید را
توسط هم یا و کالن حروف توسط
بنویسید خورد حروف.SELECTو
selectاست چیز عین.
Nangarhar University Database1 10
11. Continue…
• To select the content of
columns named
"LastName" and
"FirstName", from the
database table called
"Persons", use a SELECT
statement like this:
• SELECT LastName,
FirstName FROM Persons
•ست محتویات کردن انتخاب برایون
هایFirstNameوLastName
جدول ازPersonدستورselect
بنویسید ذیل قرار را:
• SELECT LastName,
FirstName FROM Persons
Nangarhar University Database1 11
First Name Last Name
ahmad watan
khyber afghan
12. Select All Columns:
• To select all columns from
the "Persons" table, use a *
symbol instead of column
names, like this:
• SELECT * FROM Persons
•ها ستون تمام کردن انتخاب برایاز
جدولPersonسمبول از*به
ذیل قرار ها ستون نام عوض
کنید استفاده.
• SELECT * FROM Persons
Nangarhar University Database1 12
Name Age Psot Salary
Saif 22 Eng 100
Rishad 23 Doc 200
Mjeeb 32 Guard 300
Momin 33 teacher 400
13. The SELECT DISTINCT Statement:
• The distinct keyword is used
to return only distinct
(different) values.
• Select distinct company
from orders
•کلیدی کلمهdistinctبرگشت برای
یک از متمایز های قیمت دادن
میرود بکار ذیل قرار جدول:
• Select distinct company
from orders
Nangarhar University Database1 13
Company Order Number
AWCC 234234
Roshan 56463
ZACC 4213
Afghan Telecome 6787689
14. SQL WHERE Clause:
• The WHERE clause is used
to extract only those
records that fulfill a
specified criterion.
• Syntax:
• SELECT column_name,
column_name
FROM table_name
WHERE column_name
operator value;
•کردن انتخاب برایrecordهای
مشخص شرط یک که میرود بکار
کند صدق را.
•ساختار:
• SELECT column_name,
column_name
FROM table_name
WHERE column_name
operator value;
Nangarhar University Database1 14
15. SQL WHERE Clause…
• Examples:
1. SELECT * FROM Customers WHERE Country='Mexico';
2. SELECT * FROM Customers WHERE CustomerID=1;
Nangarhar University Database1 15
16. Operators in The WHERE Clause:
Nangarhar University Database1 16
17. SQL AND & OR Operators:
• The AND & OR operators
are used to filter records
based on more than one
condition.
• The AND operator displays a
record if both the first
condition AND the second
condition are true.
• The OR operator displays a
record if either the first
condition OR the second
condition is true.
•های عملیهandوorفیلتر برای
کردنrecordاضافتر براساس ها
میرود بکار شرط یک از.
•عملیهandوقتی را ریکارد یک
دو هر صورتیکه در میدهد نشان
را دوم شرط و اول شرط ،شرط
کند صدق.
•عملیهorوقتی را ریکارد یک
یکی هر درصورتیکه میدهد نشان
صدق را دوم شرط و اول شرط از
کند.
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
17
18. Continue…
• Examples:
1. SELECT * FROM Customers WHERE Country='Germany‘ AND
City='Berlin';
2. SELECT * FROM Customers WHERE City='Berlin‘ OR
City='München';
3. SELECT * FROM Customers WHERE Country='Germany'
AND (City='Berlin' OR City='München');
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
18
19. SQL ORDER BY Keyword:
• The ORDER BY keyword is
used to sort the result-set
by one or more columns.
• The ORDER BY keyword
sorts the records in
ascending order by default.
To sort the records in a
descending order, you can
use the DESC keyword.
•کلیدی کلمهorder byمرتب برای
کردنresult-setو یک اساس بر
می بکار ستون یک از بیشتر یارود.
•کلیدی کلمهorder byپیش بطور
شکل به را ها ریکورد فرض
میکند ترتیب صعودی.ت برایرتیب
کل نزولی بشکل ریکاردها کردنمه
کلیدیdescکنید استفاده را.
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
19
20. Continue…
• Syntax:
• SELECT column_name, column_name FROM table_name
ORDER BY column_name, column_name ASC|DESC;
• Examples:
1. SELECT * FROM Customers ORDER BY Country;
2. SELECT * FROM Customers ORDER BY Country DESC;
3. SELECT * FROM Customers ORDER BY Country,
CustomerName;
1:57 AM
Gharjistan University Computer Science
Faculty Farah Branch
20