You are on page 1of 101

SQL SERVER

.

.
.

15/7/2000

GOLD NOIL

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

) (

:
:
SQL SERVER

:

6

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:

....




) (

.


.

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:

SQL
.

Tables
Rows Coloumns:


Records Fields
: ) ( )
(
:
:

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


SQL
SQL
);(

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SQL Server

Microsoft SQL Server 2000


SQL Server


SQL Server





PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


SQL






DBase
Paradox






:




PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com











Oracle 8
SQL Server 7
IBM DB2
SYbase
Informix
Borland IntraBase

Microsoft SQL Server Oracle




Microsoft SQL Server

Oracle

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com














) (








SQL





Unix

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


) (


Unix


SQL Server






Microsoft SQL Server 2000 Enterprise Manager




.




English Query Language



SQL Server Books On-Line

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

support.microsoft.com
msdn.microsoft.com/library
msdn.microsoft.com/sqlserver

SQL-Server

.

SQL-Server


) (










:



SQL Server 2000

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com




) (



SQL Server 2000

:


Client Access License

SQL Server



:









PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:



SQL Server 2000

Microsoft Visual Basic 6


Microsoft Access 2000 Developer



DLL


Microsoft Access Runtime


Oracle Developer 2000, or R:2 or R:6


Oracle Developer Runtime







SQL Server 2000

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Microsoft Data Engine




SQL Server

Oracle


Microsoft SQL Server 2000
Microsoft SQL Server 2000

Microsoft SQL Server 2000




Microsoft SQL Server 2000


SQL Server Enterprise Manager




SQL Server Client Network Utility

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


SQL Server

Enterprise Manager

SQL Server Network Utility


SQL Server Performance Monitor

Windows NT



SQL Server Profiler

Transact SQL



SQL Server Query Analyzer

Transact SQL




SQL Server Service Manager

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com




SQL Server Books Online



SQL Server OLAP

Microsoft SQL Server 2000

) (


SQL Servers



DOS





English Query Language

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


Microsoft SQL Server 2000

Microsoft SQL Server 2000 Enterprise Manager
Microsoft SQL Server 2000

Microsoft SQL Server 2000



MS SQL Server

SQL Server Agent





Autopilot


Distributed Transaction Coordinator

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


Services

Services

Master





Tempdb



Model








.mdf


.ldf

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com



SQL 2000
Configuration values
Affinity mask
allow updates
backup buffer size
Backup threads
cost threshold for
parallelism
cursor threshold
database size
default language
default sort order id
extended memory size
(MB)
fill factor (%)
free buffers
hash buckets
index create memory
(K)
Language in cache
language neutral fulltext indexing
LE threshold
maximum
LE threshold
minimum
LE threshold percent
lightweight pooling
locks
LogLRU buffers
logwrite sleep (ms)

SQL Server 6.5


Minimum
Maximum
0
2,147483,647
0
1
1
32
0
32

SQL Server 7.0


Minimum
Maximum
0
2,147,483,647
0
1
N/A
N/A
N/A
N/A

N/A

N/A

32,767

-1
2
0
0

2,147483,647
10,000
9,999
255

-1
N/A
0
0

2,147,483,647
N/A
9,999
255

N/A

N/A

2,147,483,647

0
20
4,999

100
524,288
265,003

0
N/A
N/A

100
N/A
N/A

N/A

N/A

704

1,600,000

100

100

N/A

N/A

500000

N/A

N/A

500000

N/A

N/A

1
N/A
5000
0
-1

100
N/A
2,147,483,647
2,147,483,647
500

N/A
0
5000*
N/A
N/A

N/A
1
2,147,483,647*
N/A
N/A

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

max async IO
max degree of
parallelism
max lazywrite IO
max server memory
(MB)
max text repl size
max worker threads
media retention
memory
min memory per
query (K)
min server memory
(MB)
nested triggers (bytes)
network packet size
open databases
open objects
priority boost
procedure cache
Protection cache size
query governor cost
limit
query wait (s)
RA cache hit limit
RA cache miss limit
RA delay
RA pre-fetches
RA slots-per-thread
RA worker threads
recovery flags
recovery interval
(min)
remote access
remote conn timeout

1,024

255

N/A

N/A

32

1,024

N/A

N/A

N/A

N/A

4*

2,147,483,647*

0
10
0
2800

2,147,483,647
1,024
365
1,048,576

0
10
0
N/A

2,147,483,647
1,024
365
N/A

N/A

N/A

512

2,147,483,647

N/A

N/A

0*

2,147,483,647*

0
512
5
100
0
1
1

1
32,767
32,767
2,147,483,647
1
99
8,192

0
4,096
N/A
0*
0
N/A
N/A

1
65,535
N/A
2,147,483,647*
1
N/A
N/A

N/A

N/A

2,147,483,647

N/A
1
1
0
1
1
0
0

N/A
255
255
500
1,000
255
255
1

-1
N/A
N/A
N/A
N/A
N/A
N/A
N/A

2,147,483,647
N/A
N/A
N/A
N/A
N/A
N/A
N/A

32,767

32,767

0
-1

1
32,767

0
N/A

1
N/A

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

remote login timeout


remote proc trans
remote query timeout
remote sites
resource timeout
scan for startup procs
set working set size
show advanced
options
SMP concurrency
sort pages
spin counter
tempdb in RAM (MB)
time slice
Unicode comparison
style
Unicode locale id

0
0
0
0
5
N/A
0

2,147,483,647
1
2,147,483,647
256
2,147,483,647
N/A
1

0
0
0
N/A
5
0
0

2,147,483,647
1
2,147,483,647
N/A
2,147,483,647
1
1

-1
64
1
0
50

64
511
2,147,483,647
2,044
1,000

N/A
N/A
1
N/A
50

N/A
N/A
2,147,483,647
N/A
1,000

N/A

N/A

2,147,483,647

N/A

N/A

2,147,483,647
32,767
user connections
5
32,767
0*
(server)*
user options
0
4,095
0
4,095
* Lower or upper limit for objects allocated dynamically.

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Maximum Capacity Specifications

This table specifies the maximum sizes and numbers of various objects
defined in Microsoft SQL Server databases, or referenced in
Transact-SQL statements.

Object
Batch size
Bytes per short string column
Bytes per text, ntext, or image column
Bytes per GROUP BY, ORDER BY
Bytes per index
Bytes per foreign key
Bytes per primary key
Bytes per row
Bytes in source text of a stored
procedure
Clustered indexes per table
Columns in GROUP BY, ORDER BY
Columns or expressions in a GROUP
BY WITH CUBE or WITH ROLLUP
statement
Columns per index
Columns per foreign key

Maximum sizes/numbers
SQL Server 6.5
SQL Server 7.0
65,536* Network
128 KB
Packet Size
255
8000
2 GB-2
2 GB-2
900
8060
900
900
900
900
900
900
1962
8060
Lesser of batch size
65025
or 250 MB
1
1
Limited only by
16
number of bytes
10

10

16
16

16
16

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Columns per primary key


Columns per base table
Columns per SELECT statement
Columns per INSERT statement
Connections per client
Database size
Databases per server
Filegroups per database
Files per database
File size (data)
File size (log)
Foreign key table references per table
Identifier length (in characters)
Locks per connection

16
250
4096
250
Max. value of
configured
connections
1 TB
32,767
N/A
32
32 GB
32 GB
16
30
Max. locks per
server

16
1024
4096
1024
Max. value of
configured
connections
1,048,516 TB
32,767
256
32,767
32 TB
4 TB
253
128
Max. locks per server

Locks per server

2,147,483,647

Nested stored procedure levels


Nested subqueries
Nested trigger levels
Nonclustered indexes per table
Objects concurrently open in a
server*
Objects in a database*
Parameters per stored procedure
REFERENCES per table

16
16
16
249

2,147,483,647 (static)
40% of SQL Server
memory (dynamic)
32
32
32
249

2 billion

2,147,483,647

Rows per table


SQL string length (batch size)
Tables per database

2 billion
2,147,483,647
255
1024
31
63
Limited by available Limited by available
storage
storage
128 KB
128* TDS packet size
Limited by number
2 billion
of objects in a
database

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Tables per SELECT statement

16

256
Limited by number
Triggers per table
3
of objects in a
database
UNIQUE indexes or constraints per
249 nonclustered and
249
table
1 clustered
* Database objects include all tables, views, stored procedures, extended stored
procedures, triggers, rules, defaults, and constraints. The sum of the number of
all these objects in a database cannot exceed 2,147,483,647.

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Microsoft SQL Server 2000



Microsoft SQL server 2000





Microsoft SQL Server 2000



Windows NT 4






SQL Server

Database Server Standard Edition

Microsoft Windows 2000 Server or Advance Server

Microsoft Windows 2003 server




) (

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Database Server Desktop Edition





Full text search

Replication

SQL Server 2000 OLAP Services



English Query


SQL

Database Server Desktop Edition




Local or Remote Installation

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com



Typical

Minimum

SQL Server

:
Custom







)Multilingual (850

Unicode







PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com





Microsoft SQL Server 2000

Service Pack 2




Help -> About

Service Pack


Microsoft SQL Server 2000 Enterprise Manager

SQL Server 2000

Start -> Programs -> Microsoft SQL server 2000 -> Enterprise
Manager



SQL Server 2000


PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

)Microsoft Management Console (MMC




Sql Server 2000

Transaction Server


SQL Server


SQL Server 2000




SQL Server

Action


Tools



Microsoft SQL Servers


PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


Databases
|_ master
|_ model
|_ tempdb
|_
Data Transformation Services
|_ Local Packages
|_ Repository Packages
|_ Metadata
Management
|_ SQL Server Agent
|_ Backup
|_ Current Activity
|_ Database Maintenance Planes
|_ SQL Server Logs
|_ Web Publishing
Security
|_ Logins
|_ Server Roles
|_ Linked Servers
|_ Remote Servers
Support Services
|_ Distributed Transaction Coordinator
|_ SQL Mail



PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Databases :



Databases
|_ master



Databases
|_ model




Databases
|_ tempdb

SQL Server


:
Data Transformation Services
|_ Local Packages
|_ Repository Packages
|_ Metadata

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com







:
Management

Management
|_ SQL Server Agent


Management
|_ Backup

Management
|_ Current Activity

Management
|_ Database Maintenance Planes



Management
|_ SQL Server Logs

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


SQL Server

Management
|_ Web Publishing



:
Security

Security
|_ Logins

Security
|_ Server Roles

Security
|_ Linked Servers

SQL Server

Security
|_ Remote Servers

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


:
Support Services

Support Services
|_ Distributed Transaction Coordinator

Support Services
|_ SQL Mail

SQL Server





SQL

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SQL

DROP

Drop index index_name ;


Drop index key1 ;
Drop table dd ;

PK ,FK
key1
dd

ALTER

ALTER TABLE Ppr ADD COLUMN Price


DOUBLE ;
alter table student add

Ppr Price
Add st_age in student table

(st_age number (5) ) ;


Alter table student modify ( st_age char (10) ) ;

) st_age
( null
ST_age

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

CROSS

Cross tabulation
TRANSFORM Sum(Qty) AS Total


pivot

p.city

SELECT S.SNo

select s.sno

FROM ( ( S INNER JOIN SP ON S.SNo =


SP.SNo) INNER JOIN P ON P.PNo = SP.PNo)

transform sum(qty)
as total

GROUP BY S.SNo

group by p.city
pivot p.city

PIVOT P.City ;

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

INSERT

INSERT INTO S (SNo , SName) VALUES


; ) '('S0' , 'TBA

Sp
S2shipments

:
. )
(

* INSERT INTO SP SELECT


; FROM S2shipments



:

ali






to_date :



to_date :

)insert into student (st_no , st_name


;)'values (&no , '&name

insert into student (st_no,st_name ,


st_birth_day,st_age ) values
(11, ali ,to_date
;) ('12/07/1399' , 'DD/MM/YYYY') , null
insert into student values
(11, ali ,to_date
;) ('12/07/1399' , 'DD/MM/YYYY') , null

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

CREATE

PK unique
FK
index_name

Create [unique] index index_name on


table(column1 , [column2],..)

CREATE INDEX SSNoIndex ON S (SNo)


WITH PRIMARY ;

Create table st (temp1 , temp2 ) as


Select st_no , st_name from student ;

CREATE TABLE S ( SNO TEXT(4) , SName


TEXT(12) , Status SHORT , City TEXT(12) ) ;

column1
PK
column2
FK
ssnoindex
Sno S



( temp1 , temp2 )

( st_no , st_name )
temp1 = st_no :
temp2 = st_name
S
:
Sno , Sname ,Status , City
: NULL

create table student ( st_no number(6) not null ,


st_name char(40) not null ,

: NOT NULL
table name : student

st_birth_day date

);
field : st_no , st_name ,
st_birth_day , st_mark
Key1

Create unique index key1 on emp_inf (emp_no) ;

Emp_no

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

DEFINE

define
Define descount = st_no * 10 ' ;

Select st_name ,& descount from student ;

DELETE

DELETE * FROM SP

WHERE SNo = 'S2' ;

DELETE CASCADE * FROM SP


SNo = 'S2' ;

WHERE

Delete from student where st_name='ali' ;

Sp
where
Sp
where

s

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

DECODE

col | expression

Docode ( col | expression , search1 , result1 , [


search2 . result2 , ] ,default )

search1
result1
search1 = col | expression result2
search2 =
col | expression

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

default

UPDATE

UPDATE SP SET SNo = 'S0' WHERE SNo =


'S4' ;
Update student set st_name

=(select st_name from st_inf


where st_inf.st_no = student.st_no )

where st_no in ( select st_no


from st_inf ) ;

Update student set st_name = 'ahmad
Where st_name = 'ali' ;

update student set st_name = ltrim(st_name) ;


update student set st_name = rtrim(st_name) ;

)
(

( )

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

ACCEPT

Accept password char prompt 'password : ' hide


;
Accept st_no number noprompt ;
Accept st_no number prompt 'enter number : ' ;


**


accept command
Number or char : type of
varibles
Prompt text :

Accept varible [number or char ] [ prompt or


noprompt text ] [ hide ] ;

Nopromp

Hide
)
(
Acc = accept

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SELESCT 1

Select . UNION select

Select power ( st_ digit, 2 ) , power ( 3


, 2) from student ;
SELECT * FROM S ;
SELECT * INTO Ppr FROM P ;
Select * from student ;
Select abc (st_ digit) from student ;
Select AVG ( column ) , COUNT (
distinct | all | exp)
, MAX ( distinct | all | exp) , MIN (
distinct | all | exp) , SUM ( distinct | all
| exp) , STDDEV ( distinct | all )
group by col having count(*)> 2
from student ;

select

UNION



3^2 = 3 * 3 = 9
S
Ppr P

AVG

Count

Max
Min
Sum

Stddev

Group by

group by Having
select AVG(st_age) , COUNT(distict
all st_name) , MAX(st_age) ,
MIN(st_age) ,SUM(st_age) ,
STDDEV(st_age) group by avg
having count(*) >2

All
Column
Distinct

from student ;

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Select ceil ( st_ digit) , ceil (2.99) from


student ;
SELECT Count(* ) AS N
FROM SP
WHERE PNo = 'P2' ;
SELECT Count(s.sno) AS N
FROM S ;
Select distinct st_name from student ;
SELECT DISTINCT SNo
FROM SP ;
Select distinct st_no , st_name from
student;
Select emp_name , emp_sal from
emp_inf , emp_name where
emp_name.emp_no = emp_inf.emp_no
and emp_inf.emp_sal between 120 and
200
Select emp_no from emp_inf where
emp_sal >3000
Interset select emp_no from emp_inf
where emp_no=100
Select emp_no from emp_inf where
emp_sal>3000
Union select emp_no from emp_in
where emp_no<100
Select floor ( st_ digit) , floor (100.77)
from student ;
select initcap ( st_name) , initcap
(st_no) from student;
Select jop_name from emp_inf
Where emp_sal = (select min
(emp_sal) from emp_inf)

( 2.99 )
( 3 )
S N
WHERE
S N

SP Sno

: Intersect
select

(100.77 )
( 100 )

: Subqueries
-
( : )

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

-
( : )
Select jop_name , emp_sal from
emp_inf where emp_sal in (select
min(emp_sal)from emp_inf group by
jop_name) ;
Select last-day (sysdate) from student ;
select length ('wellcome') , length
(st_name) from student ;
select lower(st_name),lower('SMALL
LETTER') from student ;

select lpad (st_name , 50 ,'-' ) ,


lpad(st_no ,10,'$') from student;


st_name wellcome


-
$
n=50

st_no number(6) or

SELECT Max(Qty ) AS MAXP2Qty


FROM SP

st_name char(40)

Qty
SP
WHERE

WHERE PNo = 'P2' ;


Select mod ( st_average , 10 ) from
student ;

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SELECT 2

select next-day(30-jun-96 ,'FRIDAY') , nextday(sysdate,'friday') from student ;


SELECT P.PNo , S.SNo , SName , Status , S.City
FROM (P INNER JOIN SP ON P.PNo = SP.PNo)
INNER JOIN S ON SP.SNo = S.Sno

SELECT
P,Sp,S

WHERE P.City = S.City


ORDER BY P.PNo , S.SNo ;
SELECT PName , City , SNo , Qty
FROM SP1 RIGHT JOIN P ON SP1.PNo =
P.PNo ;

SELECT PNo , Sum(Qty) AS TotalQty


FROM SP
GROUP BY PNo
HAVING Sum(Qty) >= 500
ORDER BY Sum(Qty) DESC , PNo ;
Select round ( st_ digit, 2 ) from student ;
Select round ( st_digit , 1 ) from student ;

Pname ,
city , Sno , QTY
SP1
RIGHT
JOIN
Pno
SP Qty

WHERE
, HAVING
WHERE

HAVING
Sum ()

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Select round (sysdate , MONTH ) , round


; (sysdate , YEAR ) from student






- $
n=50

)'select rpad (st_name , 50 ,'-' ) , rpad(st_no ,10,'$


;from student

st_no number(6) or
)st_name char(40
SELECT S.SNo , SName , Sum(Qty * Price) AS
Payment

SELECT
Ppr , SP , S
HAVING

= FROM (Ppr INNER JOIN SP ON Ppr.PNo


SP.PNo) INNER JOIN S ON SP.SNo = S.SNo
GROUP BY S.SNo , SName
HAVING Sum(Qty * Price ) <= 5000
; ORDER BY S.SNo


:
; Select sign ( st_digit ) , sign (-1) from student
-

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com



SELECT SName
FROM S

Tree SELECT

WHERE SNo IN (SELECT SNo

FROM SP

WHERE PNo IN (SELECT PNo

FROM P

Sname
S

WHERE Color = 'Red' ) ) ;


SELECT SName
TOW SELECT USE
EXISTS

FROM S
WHERE EXISTS (SELECT *

FROM SP

Sname
S

WHERE PNo = 'P2' And SNo = S.SNo );


SELECT SName
TOW SELECT USE NOT
EXISTS

FROM S
WHERE NOT EXISTS (SELECT *

FROM SP

Sname
S

WHERE PNo = 'P2' And SNo = S.SNo );


SELECT SName
TREE SELECT USE NOT
EXISTS

FROM S
WHERE NOT EXISTS ( SELECT * FROM P
WHERE NOT EXISTS (SELECT * FROM SP
WHERE SNo = S.SNo And PNo = P.PNo ) ) ;
SELECT SName
FROM S
WHERE (SELECT Count(* )

FROM SP

Sname
S

TREE SELECT USE NOT


EXISTS
Sname
S

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

WHERE SP.SNo = S.SNo)


= (SELECT Count(* ) FROM P) ;
TOW SELECT
SELECT SName FROM S
WHERE SNo IN (SELECT SNo FROM SP
WHERE PNo = 'P2' ) ;

SELECT SName , City


FROM S INNER JOIN SP ON S.SNo = SP.SNo

Sname
S

WHERE
INNER JOIN

ON

WHERE PNo = 'P2' ;


WHERE

SELECT SName , PNo , Qty

LEFT JOIN

FROM S LEFT JOIN SP ON S.SNo = SP.SNo ;


ON

SELECT SNo
TOW SELECT

FROM S
WHERE Status > (SELECT Avg(Status) FROM
S);
SELECT SNo FROM SP ;

S SNo
Sno
SP

SELECT SNo FROM S


TOW SELECT
WHERE City = (SELECT City FROM S
WHERE SNo = 'S1' ) And SNo <> 'S1' ;
Select sqrt ( abs ( st_ digit ) , sqrt (9 ) from
student ;
select st_age
NVL (st_age , 0 ) from student ;
select st_name , instr (st_name , 'a' , 1,2) from

S SNo

<==

NULL
NVL : 0

a =

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

student;
select st_name , ltrim (st_name ,'a') from student
;


n = 2 pos = 1
ba ab

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SELECT 3

ab ba


ali = ale = ALI
= NULL

>< NULL

select st_name , rtrim


; (st_name ,'a') from student
select st_name , soundex
(st_name) from student
= )where soundex (st_name
; )'soundex('ali
Select st_name , st_average
from student
; Where st_avreage is null
Select st_name , st_average
from student
Where st_avreage is not null
;

exp =st_no * 10
& ) (
exp =st_no * 10

Select st_name , st_no , & exp


; from student

&& &
exp
exp = st_no * 10

&& Select st_name , st_no ,


; exp from student

& exp
&& ) : ) (
(

.
.

SS

SS
.

; Select st_name from student


; Save ss
; Start ss
Select st_name from student

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

where
St_name = upper (&
st_name ) ;
Select st_name from student
where st_name = ' & st_enter
';
Select st_name from student
where st_no= & 1 ;
Save ss ;
Start ss 12 ;
select
st_name,instr(st_name,'a')
from student;
select st_no , decode(st_no ,
'11' , 1 , '33' , 1, 0) from
student;
Select st_no , st_name , st_no
* 3 from student ;
select st_no , st_name , st_no
- st_no from student ;
select st_no , st_name , st_no
*3 m from student ;
Select st_no , st_name from
student ;
Select st_no , st_name from
student order by st_no
,st_name ;
Select st_no , st_name from
student order by st_no ;
Select st_no , st_name from
student order by st_no DESC
;
Select st_no , st_name from
student where st_name not

:
waleed

& st_enter '

.
SS

st_no = SS
12
a


( - + / * )





( A)

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

like A% ;
Select st_no , st_name from
student where st_name like
%A% ;
Select st_no , st_name from
student where st_name like
%A ;
Select st_no , st_name from
student where st_name like
A% ;
Select st_no , st_name from
student where st_name (ali ,
waleed ) ;
Select st_no , st_name from
student where st_no in (4 , 6
, 11 ) ;
Select st_no , st_name from
student where st_no =12 or (
st_name = 'ali' and
st_average =80) ;

sea , lamp
( A)
ali , amer , hassan , ikea
( A)
ikea
( A)
ali , amer
ali or hassan =
=

select ( or , and )

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SELECT 4

Select st_no , st_name from student


where st_no >11;
Select st_no , st_name from student
where st_no between 5 and 11 ;
Select st_no , st_name from student
where st_no not between 5 and 11 ;
Select st_no , st_name from student
where st_no not in (4 , 6 , 11 ) ;
select st_no || st_name st from student
;

>= < > = )


( <=
( )
( )
<>

( st_name ,st_no)

Select substr ( st_name , POS, N) ,


substr (st_no , POS ) , substr
(waleed, POS,N) from student ;

select sysdate , sysdate-10 , sysdate+10


,
sysdate - 11/3/1999 from student;
select sysdate from dual ;

( waleed )
pos
N
date + number

date number

date date
sysdate =

dual

select to_char (sysdate , 'DAY , DDTH


MONTH YYYY') ,


to_char (sysdate , 'HH:MI:SS') from
dual ;
select to_char (sysdate , 'SCC' ) from

dual ;
select to_char (sysdate,'ww') from dual
;
sysdate
select to_date ('june 4 ,1984' ,

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

'MONTH DD YYYY') from dual ;


select to_number('123') from dual ;
Select trunc ( sysdate , MONTH ) ,
trunc ( sysdate , YEAR ) from dual ;
select trunc (st_ digit, 1 ) from student
;
select trunc (st_ digit, 2 ) from student
;
SELECT X.SNo , Y.SNo
FROM S AS X , S AS Y
WHERE X.City = Y.City AND X.SNo
<> Y.SNo ;

= ""




S AS X

X S

S AS Y

Y S

where

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

DESGRIBE

student

Describe student

TRANSLATE

a wa
select
)
(

; translate ( st_name ,'a' , 'wa') from student

SQLSERVER

.

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

*
1

DATA

ADO

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com





Data
Environment 4

Designee

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com



Add-ins >> visual data manager...


File>>new>>microsoft access>>version 7.0 mdb..


properties

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

New Table

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

name

text

number

long

integer

Long

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

data
:


data

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

data
data


datasource

data1

datafield


F5


File>>Opendatabase>>microsoft access

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Add-ins Add-in manager


Vb 6 Data FormWizard
loaded Add-Ins
Data Form Wizard Next
Access Next
Browse
Next

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Record source
available fields
column to sort
by Next
Next Finish

Project>>project1proprtis..
form11 Startup Object
.....


Add-Ins

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:
-
-

-





load

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

.

.

.



.
.

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


:



SQL

db1 tb1
:
Access

name
num
price


DAO

DAO
:
Project > Refrence Microsoft DAO 3.51
Object Library


Project Add Module

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


:
Public d As Database
Public t As Recordset

Public d t

db1
d
)(Private Sub main
)"Set d = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\db1.mdb
Form1.Show
End Sub

main

Set
d
DBEngine
Access
)Workspaces(0
Opendatabase

App.path


PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com




Project > Project1.proprties.. sub main
startup object F5

-
-
-
-


PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


t tb1
load
)(Private Sub Form_Load
)Set t = d.OpenRecordset("tb1", dbOpenTable
End Sub




Set
t
d
Openrecordset
dbopentable


PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


:
)(Private Sub showdata
' If t.RecordCount < 1 Then Exit Sub
t ' Text1.Text = t!Name
' Text2.Text = t!num
' Text3.Text = t!price
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

)(Private Sub Form_Load


)Set t = d.OpenRecordset("tb1", dbOpenTable
Call showdata
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


:

...1.....2..........3...................

:
:

:
cmd6
)(Private Sub cmd6_Click
t.MoveNext
Call showdata
End Sub

t
showdata

:
)
( cmd7
)(Private Sub cmd7_Click
t.MovePrevious
Call showdata
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:
cmd8 :
)(Private Sub cmd8_Click
t.MoveFirst
Call showdata
End Sub

:
cmd5 :
)(Private Sub cmd5_Click
t.MoveLast
Call showdata
End Sub





Movefirst movelast
:

: EOF BOF

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

If t.EOF Then t.MoveLast


If t.BOF Then t.MoveFirst


:
)(Private Sub cmd6_Click
t.MoveNext
If t.EOF Then t.MoveLast
Call showdata
End Sub

:
)(Private Sub cmd7_Click
t.MovePrevious
If t.BOF Then t.MoveFirst
Call showdata
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:

:
)(Private Sub cmd1_Click
' t.AddNew
'
"" = Text1.Text
"" = Text2.Text
"" = Text3.Text
End Sub

:



Val

:

)(Private Sub cmd2_Click


'
t!Name = Text1.Text
' )t!num = Val(Text2.Text
val
)t!price = Val(Text3.Text
t.Update
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

:

)(Private Sub cmd3_Click
' t.Edit
End Sub

:


:

)(Private Sub cmd4_Click


' t.Delete
' t.MoveNext
' If t.EOF Then t.MoveLast
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

sql

(1) SQL
:

SQL


.




Tb name number
:
number
444
534
444

name

"SQL = "select name from Tb where number = 444

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

name Tb
number SQL



:
" SQL = "select * from Tb


:
" SQL = "select name,number from Tb

:
" SQL = "select name from Tb where number = 444

> < =< => >< =


And OR
:
" SQL = "select name from Tb where number = 444 or number = 555

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

(2) SQL
:

listbox
combo box

SQL





:
tb
name
num
ahmad
1442
saleh
5425
sami
1442

:
" SQL = "select name from Tb where num = 1442


) (
T
D
:

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

)Set T=D.openrecordset(SQL,dbopendynaset


) (
SQL


List COMBO

Text Box :


List Box :
ListBox :
:
For i = 1 To n
List1.AddItem TB!name
TB.MoveNext
Next i

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

List1


: ComboBox

:



Text Box
:
name
num




:
" SQL = "select num from tb where name = text1.text



name
:
' " & ' " & text1.text

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

&




:
" '" & SQL = "select num from tb where name = '" & text1.text



:
" " & SQL = "select name from tb where num = " & text1.text




" & " & text1.text
'" & '" & text1.text

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

() SQL
:






:
tb1

tb2
deptn deptname
1

job deptno

sal
6000
12000
5500
8500
5000

name


" tb1
"



" :
tb1 ) tb2
( "

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SQL = "select name from Tb1 where deptname = (select deptname form tb2
" )where deptno = 1







'

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

() SQL
:




:
"SQL = "select left$(name,3) as k from tb1

left
name k
tb1




:
"'*" & SQL = "select name from Tb1 where name like '*" & text1.text

Like

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


Order By
:

SQL = "select name from Tb1 where name like '*" & text1.text & "*' order By
"name Asc

Order by
name
Asc Asc
Desc Asc

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Grid Flex
:
FlexGrid


db
tb namd job age
project >> combonent
ctrl+T
Microsoft FlexGrid Control 6.0

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Ok

FliexGrid

Properties
General Rows
Cols
Fixed Cols Fixed Rows
FlexGrid
Load


:

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

MSFlexGrid1.Colwidth(0) = 2000
MSFlexGrid1.Colwidth(3) = 1000

MSFlexGrid1



" " " "

MSFlexGrid1.Row = 0
MSFlexGrid1.Col = 0
" " = MSFlexGrid1.Text
MSFlexGrid1.Col = 1
"" = MSFlexGrid1.Text



Text


Text

:

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


RAM

Load



Count


TB Name Job FlexGrid
flx1
' If tb.RecordCount < 1 Then Exit Sub

' tb.MoveLast
' tb.MoveFirst
n ' n = tb.RecordCount
For i = 1 To n
' flx1.Row = i
' flx1.Col = 0
' flx1.Text = tb!Name
flx1.Col = 1
flx1.Text = tb!job
' tb1.MoveNext
Next i
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com


:
If tb.RecordCount < 1 Then Exit Sub
tb.MoveLast
tb.MoveFirst
n = tb.RecordCount
flx1.Rows = n + 1
For i = 1 To n
flx1.Row = i
flx1.Col = 0
flx1.Text = tb!Name
flx1.Col = 1
flx1.Text = tb!job
tb.MoveNext
Next i
End Sub

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

db1 tb1
:


name
mathmark
sincemark


string
integer
integer




Project >> refrences Microsoft DAO 3.51 Object library
:

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

Public d As Database
Public tb As Recordset


)Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\db1.mdb", True
)Set tb = db.OpenRecordset("tb1", dbOpenTable


Project Components Microsoft
)Chart Control 6.0 (OLEDB



AutoIncrement
True
True
ColumnCount


RowCount





:
MSChart1

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

)(Private Sub Form_Load


)Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\db1.mdb", True
)Set tb = db.OpenRecordset("tb1", dbOpenTable
MSChart1.Column = 1
MSChart1.Data = tb!mathmark
MSChart1.Column = 2
MSChart1.Data = tb!sincemark
MSChart1.RowLabel = tb!Name
End Sub

FlexGrid

mathmark
Data
sincemark


Row RowLabel Name


:

)(Private Sub Command1_Click


' tb.MoveNext
' If tb.EOF Then tb.MoveLast
MSChart1.Column = 1
MSChart1.Data = tb!mathmark
MSChart1.Column = 2
MSChart1.Data = tb!sincemark
MSChart1.RowLabel = tb!Name

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

End Sub




:
)(Private Sub Command2_Click
tb.MovePrevious
If tb.BOF Then tb.MoveFirst
MSChart1.Column = 1
MSChart1.Data = tb!mathmark
MSChart1.Column = 2
MSChart1.Data = tb!sincemark
MSChart1.RowLabel = tb!Name
End Sub


MovePrevious

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com




Properties

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

SQL SERVER

:
. XP
. XP
.MCSE
).MCDBA (SQL SERVER

.

GOLD_NOIL@YAHOO.COM

15/7/2000

GOLD NOIL

PDF created with FinePrint pdfFactory Pro trial version www.pdffactory.com

You might also like