SQL Structured Query Language IBM Ansi ISO SQL DDL SQL

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Structured Query Language SQL

% # $

!"
*/ ' -ISO, .

IBM

)* -ANSI, & '

)*

!" $ +
%

% 2 3" 1
Delete , Update , Insert , Select

+*

5 !( ( !"

" !

6!/

+1

' 14

7 !

5!(

SQL

(
! 0
1 2 3"

!" SQL 1

&

" !

) :*+

$ 1 18 .
%

)3
B

)( !9 ( !"

B -

C ? 7 ) 2D <

+ 5!(

" ! 0
% ;<= > " *" ? 5

!"

DDL
DML

!"

SQL

!"
!B

A(' !"
/ A " !

" !
0

@-view,

Data type SQL

%
%%- P)P /,O9

-yyyymmddhhmmssnnnnnn,
Date

Extract(year from d1)

!E

!E
)G

*)( 1 (
' MN,KL! I)JC
d
* 9 O9 p ) !E
/
%2/ M 9
=/ 1
% =/ O9 n 9
%
T U U1 T R)" "
%
T / @ P)9 @ )( FT
N
+ + O9 > *( )( F &) 9
S "

V/

5!( 1 K [ ( d1 #

%
H

int

!/ X

MN
=/

Y +1
Z ? + D)N
%( #
1 5!(
% 1 4 day month

@ Char(n)
@ Varchar(n)

%I)JC / 2 3" @ int


/ 2 3" @ Small int
1 @ numeric(p,d)
5!( @ Double Real
Q)* / @ Float(n)
S " 8( ) @ Date
8( ) @ Time
) " @ Timestamp
@ extract " #
'
A W"
A " ! 1 8('
!" year

$ %#

%
creat type Data name as Readsy type(s )

create type color as (" Read " , " grean" , " blue" )
31

0&

& H

14

blue , Green , Red

)?

1 ' +1

)G
1

%
P

blue , Green , Red

5!(
4# !
& ( !"

2 3" color 1 5!( 0 9 J4C !


& ( !" color 1
P 2 3"
2 3" color 5!( f1 f1 color

H
1 5!(

creat type i as numeric (5,2)

=/ O9

I)JC O9

/ ( !"

5!(

" + )G

2 3" i [
% ' $ %#

Drop type data name

%!

% ^.
1 5!( Drop

]^

0&

D 7 !C

[(
A " O)

1 Drop type color % H


7!
)
2 3" " ! 5!( 1 J
%
Creat Domain Domain name Domain value !
Creat type
3 !
100 " 1 )
P A " O 1 2 3" i [
1 5!( Creat Domain i (1, ,100) % H
Domain i VH %
Drop Domain domain name !
Drop type
3 !
%!
]^
color

,
Creat

table

table name ( A1d1

An d n )

T1

0P

Creat table table name

N_

[constraint

1]

[constraint

m]

32

4C L

) ",

D 7 !C

Creat

( A1d1

An d n )

7 !C
%

%-

0&

+ $ %#

+ D)N C ? 7 4C [ ( @ An " A1
An " A1 C ? 7 4C
R)" " @ d n " d1
table T1 ( ssn int , name char (30)) ! % H

! ()*

09 !
1

*/

N 3 !" 0&
+ )9 +

! `
DC )D 2 3"
@ +
-.
- 3 J4C
H , primary key 1a 1 4
C ? 4C 2 3" 3 DC
- K)*" , ( ) "
1
DC )D !
14 (
) " DC )D !
14 ( `
@ +
J * 9 DC
- 3 J4C
H ,% 2 3" b E
!" Q)( 1

/ 0 $ %#
)D 2 3" %
`
)D 2 3" %
DC )D \

table t1 ( ssn int primery key , name char(30))

Creat

H
%

Creat table t 2(lname char[20] , fname char[20] , degree char[20])

primery key(lname , fname)

* 9

- C ? 7 4C, + D)N 2 3"

)#

DC )D

!/

fname,lname

% )#
%

A" ( !" *( D)N

! + d D)N K !D creat

%! 1 ' 1
Creat

mark ( sn int primary key , grade

table

J , )9

) " 4C c !
7 !C +
J

@ Not

table t 3 (id int not null , name char (30))

Y+

* 9

)9

@ chek

Ai

C ? 7 4C

numerice ( 4, 2 ))

Y+
% #

14

C ? 4C 1 *+ )9
( )D 2 3" !

@ Uniqe( Ai

Aj )

&

Creat table t ( f1 char[20] , f 2 char[30] , f 3 int , uniqe( f1 , f 2 )

O)
foreign

key

14
(A i )

References

[on

Delete

casecade]

[on

update

casecade]

Reference

DC )D

&"
* 9

/1
% H

% H

( p )

check (( grade >= 00 .00 ) and ( grade < + 20 .00 ))

"

/1

Null

f2

)3

f1

P R) "
1 ).

@-2

/1
Aj

% H

;<= c !

/%3 4

Table

!/

? )D '

Reference table
W
)#
]^ !D DBMS !=( 1 4 [on Delete casecade]
! ]^ W
? )D P #
%
= ( = ' 7 !C 1 W
]^ 0*/ ! 1 4 [on Delete casecade] # \
= ' 7 !C 1 5!
W
? )D
7 ))G"
3
[on update casecade]
7 / 7 /
!"
\ )#
7 ))G" !D DBMS !=( Y 7 /
# \
)D '
W
? )D ))G" ]^ 7 !
14
1 4 Set Defult , Set Null
%!
1
9 6 N >). P NUll P "
creat table stud ( sn int , name var char (30) , city var char (40) , ave numeric (4,2) , c lg int)
primery key ( sn) , foreign key (clgn) , reference c lg
on Delet ca sec ade
on update ca sec ade

sn

+1

33

+
J * 9
( 1 '
1 *+ + D)N 7 4C C ? 7 4C * 9
1 B
DC )D ' c lg n
, c lg n
W
1 2 3" ? )D ! / c lg n
(
]^ & on update ca sec ade , on delete ca sec ade 7 / ) ?'
1 O+ N W

% H
c !
1
) DC )D 5!(
1
) c lg
"
[ *"

stud

% ( + !<( 9 Q)( ' *

]^ 0

!E

@,

Drop table table name

()*
% H

Drop table stud

@,
1

table name

' [(

di

D)N

Ai

4 6' //5#

Alter table table name add Ai d i

!
N_

]^
%+

))G"

di

table name

Ai

table name

Ai

D)N

D)N

Alter table table name modify Ai d i

Alter table table name delete Ai

!
!

creat table t ( ssn int , name char (30))

% H

Alter table t add city char (50)


Alter table t delete name

0)&="

ssn, name

% #

N_

. #

D)N

[(

+ D)N - city , A [ ( [

]^

name D)N [!

*
@ SQL

7/83 -%1 9

select part1 from part 2

[ where part 3]
part 4

> *(

34

ave

sn

+ !

0&

* 9

@ select !

- part 3 ,> Q# - part 2 , "


_ - part1 , !f" + 8D*/
) " !
%
1 '
part 4, par 3, part 2 1
Y
+ D)N [ *" part1
select from stud % H
0&
> + ! [ ( Y stud
+ 0. " [ *" c !
+ 0. " [ *"

select sn, ave from stud

VH

C ? D)N [ ( ( ! ) part1
%!
1

&"

)# !D

%+

!
%+

- C?

4C, D)N [ (

&" !"
> *( K A "

as

[(

> *(

D)N

! K
&" P
/ !E select !
O)$ *( 1 4 D)N [ ( 0 9 Distinct !
pname !
P [ *" select pname from sec ! % H
&" + [ ( select Distinct pname from sec ! % H
0&
O)
3 [ ( D)N K
O)( ! ) part1
select s # , city as shahr from stud

9 " J W !" !"


( )#

35

9 D)N *+

(!

_ 1 .2

ave

% H

part1

select sn, ave * 1.2 from stud

% H

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy