260 likes | 470 Views
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 user–request to retrieve data or information with a certain condition
E N D
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 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 )
LanguageSQL • Data Multiplication Language ( DML) لغة معالجة البيانات • Data Definition Language (DDL) لغة تعريف البيانات
Data Multiplication Language ( DML) • Select • Insert • Update • Delete
Select Statement • SELECT Field Name FROM Table Name EX: We have This Table With the name MyTable And we need to select ID Field
Solution • SelectId From MyTable Result:
EX: We have This Table With the name MyTableAnd we need to select ID ,Name Fields • SelectId, Name From MyTable Result:
To Select all table Fields • Select * From Table Name We Use * instead of write of all Fields
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
EX: From Above Table Select All data about Ali Solution Select * From MyTable Where Name =“ Ali”
INSERTStatement • Insert into Table name (Fields name) Values ( Field values) • Ex : Insert Into MyTable (ID, Name, Address, Note) Values (4,’Kindy’,’Cairo’,’SQL’)
Delete Statement • Delete From Table Name Where Condition • EX: Delete Form MyTable Where Name=‘Kindy’
UpDateStatement • UpDate Table name Set Field Name = values Ex : Up date MyTable set Yomna instead of Basma Solution Update MyTable SetName = ‘Yomna’ Where Name=‘Basma’
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))
Alter Statement • Alter Table Table Name Add <Field name> <Field Type >
EX: Alter Table MyTable Add Date 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