my sql eng: sahar. introduction to sql what is sql? when a user wants to get some information from a...

25
MY SQL Eng: SAHAR

Upload: claire-pope

Post on 25-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: MY SQL Eng: SAHAR. Introduction 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

MY SQL

Eng: SAHAR

Page 2: MY SQL Eng: SAHAR. Introduction 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

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 )

Page 3: MY SQL Eng: SAHAR. Introduction 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

Language SQL

Data Multiplication Language ( DML)

البيانات معالجة لغة

Data Definition Language (DDL)

البيانات تعريف لغة

Page 4: MY SQL Eng: SAHAR. Introduction 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

Data Multiplication Language ( DML)

Select

Insert

Update

Delete

Page 5: MY SQL Eng: SAHAR. Introduction 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

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

Page 6: MY SQL Eng: SAHAR. Introduction 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

Solution

Select Id From MyTable

Result:

ID

1

2

Page 7: MY SQL Eng: SAHAR. Introduction 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

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:

Page 8: MY SQL Eng: SAHAR. Introduction 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

To Select all table Fields

Select * From Table Name

We Use * instead of write of all Fields

Page 9: MY SQL Eng: SAHAR. Introduction 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

ID Name Salary

1 Ali 700

2 Ahmed 800

Then If We Apply This For above Example

Solution will be: Select * From MyTable

Page 10: MY SQL Eng: SAHAR. Introduction 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

Where …

If We Have a condition in using Select we can use where

Select Field name From Table Name Where Condition

Page 11: MY SQL Eng: SAHAR. Introduction 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

Where Conditions

= Equal

<> Not Equal

> More Than

< Less Than

>= More Than or equal

<= Less Than or equal

Page 12: MY SQL Eng: SAHAR. Introduction 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

EX: From Above Table Select All data

about Ali

Solution Select * From MyTable Where Name

=“ Ali”

Page 13: MY SQL Eng: SAHAR. Introduction 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

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’)

Page 14: MY SQL Eng: SAHAR. Introduction 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

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

Page 15: MY SQL Eng: SAHAR. Introduction 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

Delete StatementDelete Statement

Delete From Table Name Where Condition

EX: Delete Form MyTable Where Name=‘Kindy’Where Name=‘Kindy’

Page 16: MY SQL Eng: SAHAR. Introduction 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

The Result will be :

ID Name Address Note

1 Ibrahim Cairo VB,MYSQL

2 Yomna Geza VB.Net

3 Ola Alex ASP

Page 17: MY SQL Eng: SAHAR. Introduction 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

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’

Page 18: MY SQL Eng: SAHAR. Introduction 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

ID Name Address Note

1 Ibrahim Cairo VB,MYSQL

2 Yomna Geza VB.Net

3 Ola Alex ASP

4 Kindy Cairo SQL

Page 19: MY SQL Eng: SAHAR. Introduction 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

Data Definition Language ( DDL)

CREATE

ALTER

DROP

RENAME

Page 20: MY SQL Eng: SAHAR. Introduction 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

Create Statement

Create Table Table Name <Field name> <Field Type >

Field Type …..

Char(X)

VarChar(X)

Integer

Date

Page 21: MY SQL Eng: SAHAR. Introduction 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

EX: Create Table MyTable (ID Integer, Name

Varchar(15),Address Varchar(15),Note Varchar(50))

ID Name Address Note

Page 22: MY SQL Eng: SAHAR. Introduction 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

Alter Statement

Alter Table Table Name Add <Field name> <Field Type >

Page 23: MY SQL Eng: SAHAR. Introduction 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

EX: Alter Table MyTable Add Date

date

ID Name Address

Note Date

Page 24: MY SQL Eng: SAHAR. Introduction 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

Rename Statement

Alter Table Table Name Rename to New Name

EX: Alter Table MyTable Rename To

Sales

Page 25: MY SQL Eng: SAHAR. Introduction 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

Drop Statement

Drop Table Table Name

EX: Drop Table MyTable