SQL Myanmar PDF
SQL Myanmar PDF
SQL Myanmar PDF
www.akarphyoe.com
( ) Page 1
SQL
www.akarphyoe.com
( ) Page 2
SQL
www.akarphyoe.com
SQL
SQL
( )
( ) Page 3
SQL
www.akarphyoe.com
what is SQL?
( ) Page 4
SQL
www.akarphyoe.com
Server installation
SQL Server download
run -->
( ) Page 5
SQL
www.akarphyoe.com
( ) Page 6
SQL
www.akarphyoe.com
( ) Page 7
SQL
www.akarphyoe.com
( ) Page 8
SQL
www.akarphyoe.com
( ) Page 9
SQL
www.akarphyoe.com
SQL Server
( ) Page 10
SQL
www.akarphyoe.com
Table Basic
Relational database system table ( )
table object database data
information table table
column and row column column name data
type column row
column data records
Database kyawko object explorer
database table
kyawko database table right click new table
table data type
table data type
table dasign column
name data type table dasign -->
( ) Page 11
SQL
www.akarphyoe.com
( ) Page 12
SQL
www.akarphyoe.com
SQL - Queries
Sql
query query question
database language query
language query database
database query
select query action query select query
( ) table data
action query data insert ,updating
and deleting SQL Statement ( )
statement
semicolon (;) semicolon
database system statement MS SQL
Server (;)
( ) Page 13
SQL
www.akarphyoe.com
( ) Page 14
SQL
www.akarphyoe.com
SELECT column_name(s)
FROM table_name
( ) Page 15
SQL
www.akarphyoe.com
Select Name
from lesson
Name column data
( ) Page 16
SQL
www.akarphyoe.com
( ) Page 17
SQL
www.akarphyoe.com
Where Clause
( ) Page 18
SQL
www.akarphyoe.com
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
( ) Page 19
SQL
www.akarphyoe.com
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN
( ) Page 20
SQL
www.akarphyoe.com
And operators
record
operator where clause
( ) Page 21
SQL
www.akarphyoe.com
OR operator
( ) record table
table
( ) Page 22
SQL
www.akarphyoe.com
And
ORDER BY Keyword
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
( ) Page 23
SQL
www.akarphyoe.com
ORDER BY Name
ORDER BY DESC
( ) Page 24
SQL
www.akarphyoe.com
( ) Page 25
SQL
www.akarphyoe.com
And operators
record
operator where clause
( ) Page 26
SQL
www.akarphyoe.com
OR operator
( ) record table
table
( ) Page 27
SQL
www.akarphyoe.com
And OR
ORDER BY Keyword
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
( ) Page 28
SQL
www.akarphyoe.com
ORDER BY Name
ORDER BY DESC
( ) Page 29
SQL
www.akarphyoe.com
( ) Page 30
SQL
www.akarphyoe.com
quotes ထ‘ ‘ဒ
(1)
( ) Page 31
SQL
www.akarphyoe.com
(2)
row column
data -
column
-->
( ) Page 32
SQL
www.akarphyoe.com
(3)
UPDATE Statement
-->
UPDATE table_name
SET column_name=value, column_name=value2,...
WHERE column_name
( ) Page 33
SQL
www.akarphyoe.com
UPDATE lesson
SET phone=09258978, Country ='malaysia' ,Address = ‘kuala lumpur’
WHERE Name = 'thuthu'
( ) Page 34
SQL
www.akarphyoe.com
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
( ) Page 35
SQL
www.akarphyoe.com
Wildcards %
data wildcars %
data where clause
data column
- table
table
( ) Page 36
SQL
www.akarphyoe.com
data character
wildcard % char % table table
( ) Page 37
SQL
www.akarphyoe.com
Wildcards _
( _ ) data
table khnie select
( ) Page 38
SQL
www.akarphyoe.com
Wildcard [charlist]
[] wildcard data
- table
Name column eiei select e
or m or q [] wildcard
( ) Page 39
SQL
www.akarphyoe.com
[^ charlist] [ ] wildcard
server version
Microsoft SQL Server Express [! charlist]
[^charlist] select
DELETE Statement
( ) Page 40
SQL
www.akarphyoe.com
table row
( ) Page 41
SQL
www.akarphyoe.com
BETWEEN Operator
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
table database
table name
between operator select
--
( ) Page 42
SQL
www.akarphyoe.com
( ) Page 43
SQL
www.akarphyoe.com
AND operator
select select
database
database
SQL Joins
( ) Page 44
SQL
www.akarphyoe.com
Lesson table
List table
( ) Page 45
SQL
www.akarphyoe.com
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name= table_name2.column_name
( ) Page 46
SQL
www.akarphyoe.com
SELECT lesson.Name,lesson.Country,list.NRIC
FROM lesson
INNER JOIN list
ON lesson .p_id= list.p_id
table row
row table
( ) Page 47
SQL
www.akarphyoe.com
SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
( ) Page 48
SQL
www.akarphyoe.com
FROM lesson
LEFT JOIN test2
ON lesson .P_id =test2 .P_id
www.akarphyoe.com
( ) Page 50
SQL
www.akarphyoe.com
( ) Page 51
SQL
www.akarphyoe.com
NULL
Table column null NULL
data -
( ) Page 52
SQL
www.akarphyoe.com
column data
data SQL server
record NULL
table
table NULL ( )
IS NULL
IS NULL table NULL column
Select table
( ) Page 53
SQL
www.akarphyoe.com
IS NOT NULL
NULL data select
SQL constraintions
Constraints table data
data type table
NOT NULL
( ) Page 54
SQL
www.akarphyoe.com
UNIQUE
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT
NULL constraint
Table column null
not null constraint
not null null column
not null column row
( ) Page 55
SQL
www.akarphyoe.com
SQL Constraints
Address varchar(255),
City varchar(255)
);
( ) Page 56
SQL
www.akarphyoe.com
( ) Page 57
SQL
www.akarphyoe.com
( ) Page 58
SQL
www.akarphyoe.com
lesson
( ) Page 59
SQL
www.akarphyoe.com
List table
P-id lesson table primary key O_id list table foreign key
list table P_id lesson table P_id
( ) Page 60
SQL
www.akarphyoe.com
( ) Page 61
SQL
www.akarphyoe.com
-- column
Address varchar(255),
( ) Page 62
SQL
www.akarphyoe.com
index user
index statement data query
-->
( ) Page 63
SQL
www.akarphyoe.com
ON lesson (Name)
DROP Statement
ALTER Staement
Alter statement table column
( )
Columns -->
ALTER TABLE table_name
ADD column_name data type
( ) Page 64
SQL
www.akarphyoe.com
( ) Page 65
SQL
www.akarphyoe.com
Column datatype
data
data type
data type data type
ALTER statement
-->
DROP COLUMN
( ) Page 66
SQL
www.akarphyoe.com
databasename=tutorial ,tablename=stdent1
index user
index statement data query
-->
( ) Page 67
SQL
www.akarphyoe.com
DROP Statement
ALTER Staement
Alter statement table column
( )
Columns -->
ALTER TABLE table_name
ADD column_name data type
( ) Page 68
SQL
www.akarphyoe.com
( ) Page 69
SQL
www.akarphyoe.com
Column datatype
data
data type
data type data type
ALTER statement
-->
( ) Page 70
SQL
www.akarphyoe.com
DROP COLUMN
table column DROP DROP
-->
databasename=tutorial ,tablename=stdent1
L Date
( ) Page 71
SQL
www.akarphyoe.com
GETDATE() function
GETDATE() function sql server date and time
date à 2012-12-05
02:26:45.443 --
table clss datetime column getdate() function
table row
datetime
date datatype
Table data
( ) Page 72
SQL
www.akarphyoe.com
Datepart() function
Datepart() function table date
( )
datepart Abbreviation
year yy,yyyy,year
quarter qq,q
( ) Page 73
SQL
www.akarphyoe.com
month mm,m
datofyear dy,y
day day,
week wk,ww
Weekday dw,w
Weekday dw,w
hour hh
minutes mi,n
second ss,s
millisecond ms
microsecond mcs
datepart select
SELECT
DATEPART(YEAR,'2012-5-12') AS 'OrderYear'
( ) Page 74
SQL
www.akarphyoe.com
table --
DateADD() function
DateADD() function table date
DateADD() function argument
3 --> DATEADD(datepart,number,date)
1. Number = ( )
(-)
2012 2014
( ) Page 75
SQL
www.akarphyoe.com
FROM student4
DateDIFF()function
( ) Page 76
SQL
www.akarphyoe.com
SQL Function
( ) Page 77
SQL
www.akarphyoe.com
Aggregate Functions
Aggregate Functions
Aggregate
Functions function --
AVG() function
AVG() function column
book table
AVG()
Book table
( ) Page 78
SQL
www.akarphyoe.com
- customer name
operator column
where clause book
table
( ) Page 79
SQL
www.akarphyoe.com
Count () Function
Count () Function table Row
Count () Function NULL
Table row
(*)
( ) Page 80
SQL
www.akarphyoe.com
Max() function
Max() function column
char
Price column
( ) Page 81
SQL
www.akarphyoe.com
MIN() function
MIN() function column
char
Price column
SUM() Function
SUM() Function column
( ) Page 82
SQL
www.akarphyoe.com
Scalar Functions
Scalar Functions data
Scalar
Functions
UCASE()Function
UCASE()Function data
Uppercase SQl server
UPPER()
( ) Page 83
SQL
www.akarphyoe.com
LCASE()Function
LCASE()Function data
lowercase SQl server
LOWER() UPPER Lower
( ) Page 84
SQL
www.akarphyoe.com
MID() Function
MID() Function characters
-- server MID()
function
SELECT MID(column_name,start[,length]) FROM table_name
Start = characters ( 1)
( ) Page 85
SQL
www.akarphyoe.com
Length= characters
LEN() Fucntion
LEN() Fucntion data
SELECT LEN(column_name)
FROM table_name
( ) Page 86
SQL
www.akarphyoe.com
ROUND()Function
ROUND()Function
-- >
1. Decimals= ( )
( ) Page 87
SQL
www.akarphyoe.com
( ) Page 88
SQL
www.akarphyoe.com
data type
data type
Character String
( ) Page 89
SQL
www.akarphyoe.com
8,000
varchar(max) Variable-length character string . characters
1,073,741,824
text Variable-length character string . Maximum 2GB of
text data
Unicode String
( ) Page 90
SQL
www.akarphyoe.com
Date type
Date type combination date time value
table
time
( ) Page 91
SQL
www.akarphyoe.com
Group By statement
-- >
( ) Page 92
SQL
www.akarphyoe.com
customer
group sum() function
( ) Page 93
SQL
www.akarphyoe.com
( ) Page 94
SQL
www.akarphyoe.com
( ) Page 95
SQL
www.akarphyoe.com
( ) Page 96