my sql eng: sahar. introduction to sql what is sql? when a user wants to get some information from a...
TRANSCRIPT
MY SQL
Eng: SAHAR
Introduction to SQLIntroduction to SQL
What is SQL? 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
SQL is a query language that allows user to specify the conditions. (instead of algorithms )
Language SQL
Data Multiplication Language ( DML)
البيانات معالجة لغة
Data Definition Language (DDL)
البيانات تعريف لغة
Data Multiplication Language ( DML)
Select
Insert
Update
Delete
Select StatementSelect Statement
SELECTSELECT Field NameField Name FROM FROMTable NameTable Name
EX: We have This Table With the name EX: We have This Table With the name MyTableMyTable
And we need to select ID FieldAnd we need to select ID Field
ID Name Salary
1 Ali 700
2 Ahmed 800
Solution
Select Id From MyTable
Result:
ID
1
2
EX:EX: We have This Table With the name We have This Table With the name MyTableMyTableAnd we need to select ID ,Name Fields And we need to select ID ,Name Fields
Select Id, Name From MyTable ID Name
1 Ali
2 Ahmed
Result:
To Select all table Fields
Select * From Table Name
We Use * instead of write of all Fields
ID Name Salary
1 Ali 700
2 Ahmed 800
Then If We Apply This For above Example
Solution will be: Select * From MyTable
Where …
If We Have a condition in using Select we can use where
Select Field name From Table Name Where Condition
Where Conditions
= Equal
<> Not Equal
> More Than
< Less Than
>= More Than or equal
<= Less Than or equal
EX: From Above Table Select All data
about Ali
Solution Select * From MyTable Where Name
=“ Ali”
INSERTINSERT StatementStatement
Insert into Insert into Table nameTable name ( (Fields nameFields name) ) Values ( Values ( Field valuesField values))
Ex : Ex : Insert Into MyTable (ID, Name, Address, ID, Name, Address, Note) Values (4,’Kindy’,’Cairo’,’SQL’)Note) Values (4,’Kindy’,’Cairo’,’SQL’)
The Result will be :
ID Name Address Note
1 Ibrahim Cairo VB,MYSQL
2 Basma Geza VB.Net
3 Ola Alex ASP
4 Kindy Cairo SQL
Delete StatementDelete Statement
Delete From Table Name Where Condition
EX: Delete Form MyTable Where Name=‘Kindy’Where Name=‘Kindy’
The Result will be :
ID Name Address Note
1 Ibrahim Cairo VB,MYSQL
2 Yomna Geza VB.Net
3 Ola Alex ASP
UpDateUpDate StatementStatement
UpDate UpDate Table nameTable name Set Set Field Name = Field Name = valuesvalues
Ex : Ex : Up date MyTable set YomnaYomna instead of BasmaBasma
Solution
Update MyTable Set NameName = ‘Yomna’ Where = ‘Yomna’ Where NameName=‘Basma’=‘Basma’
ID Name Address Note
1 Ibrahim Cairo VB,MYSQL
2 Yomna Geza VB.Net
3 Ola Alex ASP
4 Kindy Cairo SQL
Data Definition Language ( DDL)
CREATE
ALTER
DROP
RENAME
Create Statement
Create Table Table Name <Field name> <Field Type >
Field Type …..
Char(X)
VarChar(X)
Integer
Date
EX: Create Table MyTable (ID Integer, Name
Varchar(15),Address Varchar(15),Note Varchar(50))
ID Name Address Note
Alter Statement
Alter Table Table Name Add <Field name> <Field Type >
EX: Alter Table MyTable Add Date
date
ID Name Address
Note Date
Rename Statement
Alter Table Table Name Rename to New Name
EX: Alter Table MyTable Rename To
Sales
Drop Statement
Drop Table Table Name
EX: Drop Table MyTable