Вы находитесь на странице: 1из 59

..

SQL MS SQL SERVER,


ORACLE, VFP ACCESS:

2008


-
()

..

SQL MS SQL SERVER,

ORACLE, VFP ACCESS:




2008

681.3.06
31.965
30

:
. . , , .. ,
. . , , .. ,

-
-

,
,
.

..
30 SQL MS SQL SERVER, ORACLE, VFP ACCESS:
. : - , 2008. 57 .
ISBN 978 5 93204 422 3

SQL
MS
SQL Server, Oracle, VFP, Access, ,

. ,
,
,
.
. 16. . 22 . .: 18 .

ISBN 978 5 93204 422 3

.., 2008


1. SQL .............................. 4
1.1. ................................................................... 4
1.2.
SQL ...................................................................... 8
2. SQL ......................................................................... 40
2.1. .................................................. 40
2.2.
.................................. 41
2.3. ................................. 47
2.4.
................ 49
3. .......................................................................... 56
.......................................................................... 57

1. SQL

,
SQL .
,
.
1.1.
1 (. 1 3)
, ,

(, , ..).
Staff
T_number
Surname
Name
Lastname
Birthday
Phone
Post
Date_input
Type_post

Pay
T_number

Items_pay
Code_pay
Item_pay
Item_sum
Code_Items

Code_pay
Pay_day
Sum_pay

. 1.


-- :
1. Staff.T_number- Pay.T_number.
2. Pay.Code_pay - Items_pay.Code_pay.
1
( Staff)

T_number


Integer


()

Surname
Name
Lastname
Birthday
Phone
Post
Type_post

Character
Character
Character
Date
Numeric
Character
Character







(, , )

Date_input

Date

2
( Pay)

T_number


Integer

Code_pay
Pay_day
Sum_pay

Integer
Date
Numeric


,

()


3


( Items_pay)

Code_pay
Item_pay


Integer
Character

Item_sum
Code_Items

Numeric
Integer



,
( , )

4 6 ,

.
4
Staff
T_number Surname Name Lastname Birthday Phone
1

12.04.2000

14.11.1999

30.11.2000

10.02.1998

14.06.1954 451263


14.06.1981 145236


05.12.1970 365462

15.05.1981 121212

25.06.1980

11

18.11.2003

15

12.11.1979

67

12.01.1971 124563

Type_post Date_input

Post

30.05.1970 156462

12.03.1960 145214

5
Pay ()
T_number Code_pay Pay_day Sum_pay
1
1
01.01.2003 2544.00
1
2
01.02.2003 4521.00
5

. 5
T_number Code_pay Pay_day Sum_pay
1
3
01.03.2003 12542.00
2
4
01.01.2003 1452.00
2
5
01.02.2003 2145.00
2
6
01.03.2003 2135.00
3
7
01.01.2003 4511.00
3
8
01.02.2003 1542.00
3
9
01.03.2003 1542.00
4
10
01.03.2003 2456.00
6
Items_pay ()
Code_pay
1
1
1
1
1
2
2
2
3
3
10
10
10
10

Item_pay

Item_sum Code_Items
124.00
1
-451.00
2
1457.00
3
4512.00
4
145.00
5
4656.00
6
-415.00
7
326.00
8
1654.00
9
1213.00
-154.00
1456.00
1245.00

10
11
12
13

-452.00

14


.
SQL Server:
CREATE DATABASE DB_pay
/* DB_pay,
, */
USE DB_pay
/* DB_pay*/
CREATE TABLE Staff(T_number INT IDENTITY(1,1) PRIMARY KEY,
Surname CHAR(25), Name CHAR(25), Lastname CHAR(25), Birthday

SMALLDATETIME, Phone Numeric(13,0), Post CHAR(30), Type_post CHAR(8)


DEFAULT '', Date_input SMALLDATETIME DEFAULT Getdate())
CREATE TABLE Pay(T_number INT FOREIGN KEY REFERENCES
Staff(T_number) ON UPDATE CASCADE, Code_pay INT IDENTITY(1,1)
PRIMARY KEY, Pay_day SMALLDATETIME DEFAULT Getdate(), Sum_pay
Numeric(8,2))
CREATE TABLE Items_pay(Code_pay INT FOREIGN KEY REFERENCES
Pay(Code_pay), Item_pay CHAR(20) DEFAULT '', Item_sum
Numeric(8,2), Code_Items BIGINT IDENTITY(1,1) PRIMARY KEY)
ORACLE:
/*
*/
CREATE USER "ADMIN_PAY"
PROFILE "DEFAULT"
IDENTIFIED BY "P@ssw0rd"
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP"
ACCOUNT UNLOCK;
GRANT "CONNECT" TO "ADMIN_PAY" WITH ADMIN OPTION;
GRANT "DBA" TO "ADMIN_PAY" WITH ADMIN OPTION;
GRANT "EXP_FULL_DATABASE" TO "ADMIN_PAY" WITH ADMIN
OPTION;
/*
*/
CREATE TABLESPACE "DB_PAY"
LOGGING
DATAFILE 'C:\ORACLE\ORADATA\ORCL\DB_PAY.dbf' SIZE 5M
EXTENT
MANAGEMENT LOCAL;
/* ADMIN_PAY
DB_PAY*/
ALTER USER "ADMIN_PAY" DEFAULT TABLESPACE "DB_PAY";
CREATE
TABLE
ADMIN_PAY.Staff
(T_number
NUMBER(5),
CONSTRAINT "ID_STAFF" PRIMARY KEY(T_number) USING INDEX
TABLESPACE "DB_PAY", Surname CHAR(25), Name CHAR(25), Lastname
7

CHAR(25), Birthday DATE, Phone NUMBER(13,0), Post CHAR(30), Type_post


CHAR(8) DEFAULT '', Date_input DATE DEFAULT Sysdate)
TABLESPACE "DB_PAY";
CREATE
TABLE
ADMIN_PAY.Pay(T_number
CONSTRAINT "ID_STAFF_FK" FOREIGN KEY(T_number)
ADMIN_PAY.Staff(T_number), Code_pay NUMBER(6),
"ID_PAY" PRIMARY KEY(Code_pay) USING INDEX
"DB_PAY", Pay_day DATE DEFAULT Sysdate, Sum_pay
TABLESPACE "DB_PAY";

NUMBER(5),
REFERENCES
CONSTRAINT
TABLESPACE
NUMBER(8,2))

CREATE TABLE ADMIN_PAY.Items_pay(Code_pay NUMBER(6),


CONSTRAINT "ID_PAY_FK" FOREIGN KEY(Code_pay) REFERENCES
ADMIN_PAY.Pay(Code_pay), Item_pay CHAR(20) DEFAULT '',
Item_sum Numeric(8,2), Code_Items NUMBER(8) PRIMARY KEY USING
INDEX TABLESPACE "DB_PAY") TABLESPACE "DB_PAY";
--
CREATE SEQUENCE ADMIN_PAY.ID_STAFF_SEQ INCREMENT BY
1 START WITH 1 MAXVALUE 99999 MINVALUE 1 NOCYCLE CACHE
20 NOORDER;
CREATE SEQUENCE ADMIN_PAY.ID_PAY_SEQ INCREMENT BY 1
START WITH 1 MAXVALUE 999999 MINVALUE 1 NOCYCLE CACHE 20
NOORDER;
CREATE SEQUENCE ADMIN_PAY.ID_ITEM_SEQ INCREMENT BY 1
START WITH 1 MAXVALUE 99999999 MINVALUE 1 NOCYCLE CACHE
20 NOORDER;
1.2.
SQL
.
1. Staff
:
VFP, MS SQL Server, Access:
SELECT * FROM Staff ORDER BY T_number
Oracle:
SELECT * FROM ADMIN_PAY.Staff ORDER BY T_number;

SELECT , SQL ,
,
.
* ,
,
( ALL).
FROM ,
/ ( ,
) .
MS SQL Server , DB_Pay
, USE DB_Pay.
Oracle
, .
ADMIN_PAY.
2. , , , ,

:
VFP, MS SQL Server, Access:
SELECT Surname, Name, Lastname, Post FROM Staff ORDER BY Post
ASC, Surname DESC
Oracle:
SELECT Surname, Name, Lastname, Post FROM ADMIN_PAY.Staff
ORDER BY Post ASC, Surname DESC;
ORDER BY ,
,
.
, .
ASC ,
ASC.
DESC ,
DESC.
,
:
;

..
9

3. Pay
(.
2):
VFP, MS SQL Server, Access:
SELECT T_number, Pay_day FROM Pay ORDER BY Pay_day DESC
Oracle:
SELECT T_number, Pay_day FROM ADMIN_PAY.Pay ORDER BY
Pay_day DESC;
T_Number
1
2
3
4
1
2
3
1
2
3

Pay_day
01.03.2003
01.03.2003
01.03.2003
01.03.2003
01.02.2003
01.02.2003
01.02.2003
01.01.2003
01.01.2003
01.01.2003

. 2.

.
4. Staff ,
: Name, Lastname,
Surname, Post, Date_input, Phone, Birthday, T_number, Type_post (. 3):
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, Post, Date_input, Phone, Birthday,
T_number, Type_post FROM Staff
Oracle:
SELECT Name, Lastname, Surname, Post, Date_input, Phone, Birthday,
T_number, Type_post FROM ADMIN_PAY.Staff;
Surname
Post

Date_input Phone
Birthday
T_number Type_post
12.04.2000 124563 12.01.1971
1

14.11.1999 451263 14.06.1954


2

30.11.2000 145236 14.06.1981


3

10.02.1998 365462 05.12.1970


67

25.06.1980 121212 15.05.1981


4

18.11.2003 156462 30.05.1970


11

12.11.1979 145214 12.03.1940


15

. 3.
10

5. Pay ,
: Sum_pay, Pay_day, T_number,
Code_pay:
VFP, MS SQL Server, Access:
SELECT Sum_pay, Pay_day, T_number, Code_pay FROM Pay
Oracle:
SELECT
Sum_pay,
ADMIN_PAY.Pay;

Pay_day,

T_number,

Code_pay

FROM

() .
6. , , ( Surname,
Name, Lastname), ( Sum_pay)
( Pay_day):
VFP, MS SQL Server, Access:
SELECT Surname, Name, Lastname, Sum_pay, Pay_day FROM Staff, Pay
WHERE Staff.T_number = Pay.T_number
Oracle:
SELECT Surname, Name, Lastname, Sum_pay, Pay_day FROM
ADMIN_PAY.Staff, ADMIN_PAY.Pay WHERE Staff.T_number =
Pay.T_number;
WHERE WHERE ,
. ,
, ,
,
,
AND OR.
7. ,
, (.
4):
VFP, MS SQL Server, Access:
SELECT T_number, Pay_day, Item_pay, Item_sum FROM Pay, Items_pay
WHERE Pay.Code_pay = Items_pay.Code_pay ORDER BY T_number
Oracle:
SELECT
T_number,
Pay_day,
Item_pay,
Item_sum
FROM
ADMIN_PAY.Pay, ADMIN_PAY.Items_pay WHERE Pay.Code_pay =
Items_pay.Code_pay ORDER BY T_number;
11

T_Number
1
1
1
1
1
1
1
1
1

Pay_day
01.01.2003
01.01.2003
01.01.2003
01.01.2003
01.01.2003
01.02.2003
01.02.2003
01.02.2003
01.03.2003

1
4
4
4
4

01.03.2003
01.03.2003
01.03.2003
01.03.2003
01.03.2003

Item_pay

Item_sum
124.00
-451.00
1457.00
4512.00
145.00
4656.00
-415.00
326.00
1654.00
1213.00
-154.00
1456.00
1245.00
-452.00

. 4.

8. ,

:
VFP, MS SQL Server, Access:
SELECT Surname, Staff.T_number, Sum_pay, Pay_day, Item_pay,
Item_sum FROM Staff, Pay, Items_pay WHERE (Staff.T_number =
Pay.T_number) AND (Pay.Code_pay = Items_pay.Code_pay)
Oracle:
SELECT Surname, Staff.T_number, Sum_pay, Pay_day, Item_pay,
Item_sum
FROM
ADMIN_PAY.Staff,
ADMIN_PAY.Pay,
ADMIN_PAY.Items_pay WHERE (Staff.T_number = Pay.T_number) AND
(Pay.Code_pay = Items_pay.Code_pay);

,
, . : Staff.T_number
AND " ",
,
. ,
=,
WHERE.
,
,
.

12

: WHERE
;
,
" ", .
.
9. ,
:
MS SQL Server, Access ( ,
):
SELECT Surname, Name, Lastname, Post FROM Staff WHERE Post =
''
,
(. 4)
'' ''.
VFP .
VFP :
SET ANSI ON
&&
SELECT Surname, Name, Lastname, Post FROM Staff WHERE Post =
''
VFP (. 5):
SET ANSI OFF
&&
SELECT Surname, Name, Lastname, Post FROM Staff WHERE Post =
''
Surname

Name

Lastname

Post

. 5.

Oracle ( ,
):
SELECT Surname, Name, Lastname, Post FROM ADMIN_PAY.Staff
WHERE Post = '';
' '
. , .

13

.
10. ,
:
VFP, MS SQL Server, Access:
SELECT Surname, Name, Lastname, Post FROM Staff WHERE
NOT(Type_post = '')
MS SQL Server, Type_post
NULL, ,
NOT( ) .
Oracle:
SELECT Surname, Name, Lastname, Post FROM ADMIN_PAY.Staff
WHERE NOT(Type_post = '');
Oracle MS SQL Server,
Type_post NULL,
.
NOT( ) " ".
, NOT( )
.
,
.
11. , ,
(. 6):
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, Date_input FROM Staff WHERE
NOT(Post = '')
Oracle:
SELECT
Name,
Lastname,
Surname,
Date_input
ADMIN_PAY.Staff WHERE NOT(Post = '');
Name

Lastname

Surname

Date_input
14.11.1999
30.11.2000
10.02.1998
25.06.1980
12.11.1979

. 6. ,

14

FROM

(Between).
12.
01.01.2003 01.03.2003 (. 7):
VFP:
SELECT Name, Lastname, Surname, Sum_pay, Pay_day FROM Staff, Pay
WHERE (Staff.T_number = Pay.T_number) AND Pay_day BETWEEN
CTOD(01.01.2003) AND CTOD(01.03.2003)
Name

Lastname

Surname

Sum_pay
2544.00
4521.00
12542.00
1452.00
2145.00
2135.00
4511.00
1542.00
1542.00
2456.00

Pay_day
01.01.2003
01.02.2003
01.03.2003
01.01.2003
01.02.2003
01.03.2003
01.01.2003
01.02.2003
01.03.2003
01.03.2003

. 7.

MS SQL Server:
SELECT Name, Lastname, Surname, Sum_pay FROM Staff, Pay WHERE
(Staff.T_number = Pay.T_number) AND Pay_day BETWEEN '1-JAN-2003'
AND '1-MAR-2003'

SET DATEFORMAT dmy


SELECT Name, Lastname, Surname, Sum_pay FROM Staff, Pay WHERE
(Staff.T_number = Pay.T_number) AND Pay_day BETWEEN '1-01-2003' AND
'1-03-2003'
Access:
SELECT Name, Lastname, Surname, Sum_pay FROM Staff, Pay WHERE
(Staff.T_number = Pay.T_number) AND Pay_day BETWEEN #01.01.2003#
AND #01.03.2003#
Oracle:
SELECT Name, Lastname, Surname, Sum_pay FROM ADMIN_PAY.Staff,
ADMIN_PAY.Pay WHERE (Staff.T_number = Pay.T_number) AND Pay_day
BETWEEN '1-JAN-2003' AND '1-MAR-2003';

SELECT Name, Lastname, Surname, Sum_pay FROM ADMIN_PAY.Staff,


ADMIN_PAY.Pay WHERE (Staff.T_number = Pay.T_number) AND Pay_day

15

BETWEEN to_date('1-01-2003','dd-mm-yyyy') AND to_date('1-03-2003','ddmm-yyyy');


BETWEEN .
,
.
.
Access # # ( ..).
VFP
CTOD( ).
MS SQL Server
-- ( JAN, FEB,
MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC).
13. ,
12.03.2000 15.06.2000, :
VFP:
SELECT Name, Lastname, Surname, Post FROM Staff WHERE Date_input
BETWEEN CTOD(12.03.2000) AND CTOD(15.06.2000)
MS SQL Server:
SELECT Name, Lastname, Surname, Post FROM Staff WHERE Date_input
BETWEEN '12-MAR-2000' AND '15-JUN-2000'
MS Access:
SELECT Name, Lastname, Surname, Sum_day FROM Staff WHERE
Date_input BETWEEN #12.03.2000# AND #15.06.2000#
Oracle:
SELECT Name, Lastname, Surname, Post FROM ADMIN_PAY.Staff
WHERE Date_input BETWEEN to_date('12-03-2000', 'dd-mm-yyyy') AND
to_date('15-06-2000', 'dd-mm-yyyy');
14. ,
111111 222222:
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, Phone FROM Staff WHERE Phone
BETWEEN 111111 AND 222222
Oracle:
SELECT Name, Lastname, Surname, Phone FROM ADMIN_PAY.Staff
WHERE Phone BETWEEN 111111 AND 222222;

16

15. ,
:
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname FROM Staff WHERE Surname
BETWEEN '' AND ''
Oracle:
SELECT Name, Lastname, Surname FROM ADMIN_PAY.Staff WHERE
Surname BETWEEN '' AND '';
(In).
16.
, , :
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, Post FROM Staff WHERE Post
IN(' ', ' ', '
')
Oracle:
SELECT Name, Lastname, Surname, Post FROM ADMIN_PAY.Staff
WHERE Post IN(' ', ' ',
' ');
IN( ) . ,

, .. , IN( ).
17. ,
: , , :
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname FROM Staff, Pay, Items_pay WHERE
(Staff.T_number
=
Pay.T_number)
AND
(Pay.Code_pay
=
Items_pay.Code_pay) AND (Item_pay IN('', ' ',
''))
Oracle:
SELECT Name, Lastname, Surname FROM ADMIN_PAY.Staff,
ADMIN_PAY.Pay, ADMIN_PAY.Items_pay WHERE (Staff.T_number =
Pay.T_number) AND (Pay.Code_pay = Items_pay.Code_pay) AND (Item_pay
IN('', ' ', ''));

17

18. 4, 67, 45, 77


(. 8):
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, T_Number FROM Staff WHERE
T_Number IN(4, 67, 45, 77)
Oracle:
SELECT
Name,
Lastname,
Surname,
T_Number
FROM
ADMIN_PAY.Staff WHERE T_Number IN(4, 67, 45, 77);
Name

Lastname

Surname

T_number
67
4

. 8.

Like.
19. ,
:
MS SQL Server( ):
SELECT DISTINCT Item_pay FROM Items_pay WHERE Item_pay LIKE
'%'
Access:
SELECT DISTINCT Item_pay FROM Items_pay WHERE Item_pay LIKE
*
Oracle ( ):
SELECT DISTINCT Item_pay FROM ADMIN_PAY.Items_pay WHERE
Item_pay LIKE '%';
LIKE( ) ,
. % * ,
.
_ ? ,
. Access: "?*"
, ,
, .
20. ,
:
VFP, MS SQL Server:
SELECT Name, Lastname, Surname FROM Staff WHERE Lastname LIKE
'%%'

18

Access:
SELECT Name, Lastname, Surname FROM Staff WHERE Lastname LIKE
**
Oracle:
SELECT Name, Lastname, Surname FROM ADMIN_PAY.Staff WHERE
Lastname LIKE '%%';
21. ,
(. 9):
VFP, MS SQL Server:
SELECT DISTINCT Post FROM Staff WHERE Post LIKE '%'
Post

. 9.
Like

Access:
SELECT DISTINCT Post FROM Staff WHERE Post LIKE *
Oracle:
SELECT DISTINCT Post FROM ADMIN_PAY.Staff WHERE Post LIKE
'%';

22. , 15.03.2003
2000 3000 .:
VFP:
SELECT Name, Lastname, Surname FROM Staff, Pay WHERE
(Staff.T_number = Pay.T_number) AND Pay_day = CTOD(15.03.2003) AND
((Sum_pay>=2000) AND (Sum_pay<3000))
MS SQL Server:
SELECT Name, Lastname, Surname FROM Staff, Pay WHERE
(Staff.T_number = Pay.T_number) AND Pay_day = '15-MAR-2003' AND
((Sum_pay>=2000) AND (Sum_pay<3000))
Access:
SELECT Name, Lastname, Surname FROM Staff, Pay WHERE
(Staff.T_number = Pay.T_number) AND Pay_day = #15.03.2003# AND
((Sum_pay>=2000) AND (Sum_pay<3000))
Oracle:
SELECT Name, Lastname, Surname FROM ADMIN_PAY.Staff,
ADMIN_PAY.Pay WHERE (Staff.T_number = Pay.T_number) AND Pay_day
= '15-MAR-2003' AND ((Sum_pay>=2000) AND (Sum_pay<3000));
19


SELECT Name, Lastname, Surname FROM ADMIN_PAY.Staff,
ADMIN_PAY.Pay WHERE (Staff.T_number = Pay.T_number) AND Pay_day
= to_date('15-MAR-2003', 'dd-mm-yyyy') AND ((Sum_pay>=2000) AND
(Sum_pay<3000));
23.
12 30 ,
5000 .:
VFP, MS SQL Server, Access:
SELECT DISTINCT Name, Lastname, Surname, Staff.T_number FROM
Staff, Pay WHERE (Staff.T_number = Pay.T_number) AND ( (Staff.T_Number
BETWEEN 12 AND 30) OR Sum_pay>5000)
Oracle:
SELECT DISTINCT Name, Lastname, Surname, Staff.T_number FROM
ADMIN_PAY.Staff, ADMIN_PAY.Pay WHERE (Staff.T_number =
Pay.T_number) AND ( (Staff.T_Number BETWEEN 12 AND 30) OR
Sum_pay>5000);
24. 01.01.1950
01.01.1960 10 150 (. 10):
VFP:
SELECT Name, Lastname, Surname, Birthday, T_number FROM Staff
WHERE
(Birthday
BETWEEN
CTOD(01.01.1950)
AND
CTOD(01.01.1960)) OR (T_number>=10 AND T_number<=150)
Name

Lastname

Surname

Birthday
14.06.1954
05.12.1970
30.05.1970
12.03.1960

T_number
2
67
11
15

. 10.

MS SQL Server:
SELECT Name, Lastname, Surname, Birthday, T_number FROM Staff
WHERE (Birthday BETWEEN '01-JAN-1950' AND '01-JAN-1960') OR
(T_number>=10 AND T_number<=150)
Access:
SELECT Name, Lastname, Surname, Birthday, T_number FROM Staff
WHERE (Birthday BETWEEN #01.01.1950# AND #01.01.1960#) OR
(T_number>=10 AND T_number<=150)
20

Oracle:
SELECT Name, Lastname, Surname, Birthday, T_number FROM
ADMIN_PAY.Staff WHERE (Birthday BETWEEN '01-JAN-1950' AND '01JAN-1960') OR (T_number>=10 AND T_number<=150);
( ,
JOIN).
25. ,
: , , :
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname FROM Staff INNER JOIN Pay
INNER JOIN Items_pay ON Pay.Code_pay = Items_pay.Code_pay ON
Staff.T_number = Pay.T_number WHERE Item_pay IN('', '
', '')

SELECT Name, Lastname, Surname FROM (Staff INNER JOIN Pay ON


Staff.T_number = Pay.T_number) INNER JOIN Items_pay ON Pay.Code_pay =
Items_pay.Code_pay WHERE Item_pay IN('', ' ',
'')
Oracle:
SELECT Name, Lastname, Surname FROM (ADMIN_PAY.Staff INNER
JOIN ADMIN_PAY.Pay ON Staff.T_number = Pay.T_number) INNER JOIN
ADMIN_PAY.Items_pay ON Pay.Code_pay = Items_pay.Code_pay WHERE
Item_pay IN('', ' ', '');
INNER JOIN ,
,
, ON.
LEFT JOIN ,
,
,
.
RIGHT JOIN ,
,
,
.
ON ,
.
26. ,
2000 3000 . (. 11):
21

VFP, MS SQL Server, Access:


SELECT DISTINCT Name, Lastname, Surname FROM Staff INNER JOIN
Pay ON Staff.T_number = Pay.T_number WHERE (Sum_pay>=2000) AND
(Sum_pay<3000)
Oracle:
SELECT
DISTINCT
Name,
Lastname,
Surname
FROM
ADMIN_PAY.Staff INNER JOIN ADMIN_PAY.Pay ON Staff.T_number =
Pay.T_number WHERE (Sum_pay>=2000) AND (Sum_pay<3000);
Name

Lastname

Surname

. 11.

27. ,
:
VFP, MS SQL Server, Access:
SELECT Pay.Code_pay FROM Pay INNER JOIN Items_pay ON
Pay.Code_pay = Items_pay.Code_pay WHERE Item_pay = ' '
Oracle:
SELECT Pay.Code_pay FROM ADMIN_PAY.Pay INNER JOIN
ADMIN_PAY.Items_pay ON Pay.Code_pay = Items_pay.Code_pay WHERE
Item_pay = ' ';
28. ,
:
VFP, MS SQL Server, Access:
SELECT DISTINCT Name, Lastname, Surname FROM Staff INNER JOIN
Pay INNER JOIN Items_pay ON Pay.Code_pay = Items_pay.Code_pay ON
Staff.T_number = Pay.T_number WHERE Item_pay = ' '
Oracle:
SELECT
DISTINCT
Name,
Lastname,
Surname
FROM
ADMIN_PAY.Staff INNER JOIN ADMIN_PAY.Pay INNER JOIN
ADMIN_PAY.Items_pay ON Pay.Code_pay = Items_pay.Code_pay ON
Staff.T_number = Pay.T_number WHERE Item_pay = ' ';
.
29. ,
(. 12):
22

VFP, Access:
SELECT Name, Lastname, Surname, Post, (Date() - Date_input)/365.25
FROM Staff ORDER BY Date_input
MS SQL Server:
SELECT Name, Lastname, Surname, Post, CAST((GetDate() - Date_input)
AS Bigint)/365.25 FROM Staff ORDER BY Date_input
Oracle:
SELECT Name, Lastname, Surname, Post, (SysDate - Date_input)/365.25
FROM ADMIN_PAY.Staff ORDER BY Date_input;
Name

Lastname

Surname

Post

Exp_5
25.1061
24.4873
6.8583
5.1006
4.6899
4.0548
1.0897

. 12.

30. ,
,
:
VFP:
SET DATE TO GERMAN
&& ..
SELECT
Name,
Lastname,
Surname,
Post,
Birthday,
CTOD(str(day(Birthday))+'.'+str(month(Birthday))+'.'+str(YEAR(Date())))DATE() FROM Staff Where CTOD (str(day(Birthday)) + ' . ' + str
(month(Birthday)) + ' . ' + str (YEAR(Date())))-DATE()) >0
MS SQL SERVER:
SET DATEFORMAT dmy
-- ..
SELECT Name, Lastname, Surname, Post, Birthday,
DATEDIFF(day,
getdate(),
CAST(str(day(Birthday))+
'.'
+
str(month(Birthday)) + '.' +str(YEAR(GetDate())) AS datetime)) AS [
] FROM Staff Where DATEDIFF(day, getdate(),
CAST(str(day(Birthday)) + '.' + str(month(Birthday)) + '.' +
str(YEAR(GetDate())) AS datetime))>0
23

Oracle:
SELECT Surname, TO_NUMBER( TO_DATE( ( to_char(Birthday,
'dd')||'.'||to_char(Birthday, 'mm')||'.'||to_char(Sysdate,'yyyy') ), 'DD-MM-YYYY')SYSDATE) FROM ADMIN_PAY.Staff WHERE TO_NUMBER( TO_DATE(
( to_char( Birthday,'dd')||'.'||to_char( Birthday,'mm')||'.'||to_char(Sysdate,'yyyy') ),
'DD-MM-YYYY')-SYSDATE) >0;
31. , ,
,
:
VFP, MS SQL Server, Access:
SELECT Staff.T_number, Name, Surname, Pay_day, Sum_pay, (Sum_payItem_sum) FROM Staff INNER JOIN Pay INNER JOIN Items_pay ON
Pay.Code_pay = Items_pay.Code_pay ON Staff.T_number = Pay.T_number
WHERE Item_pay = ' '
Oracle:
SELECT Staff.T_number, Name, Surname, Pay_day, Sum_pay, (Sum_payItem_sum) FROM ADMIN_PAY.Staff INNER JOIN ADMIN_PAY.Pay
INNER
JOIN
ADMIN_PAY.Items_pay
ON
Pay.Code_pay
=
Items_pay.Code_pay ON Staff.T_number = Pay.T_number WHERE Item_pay
= ' ';
, ..
.

.
32. , -
:
VFP, MS SQL Server, Access:
SELECT AVG(Sum_pay) FROM Pay
Oracle:
SELECT AVG(Sum_pay) FROM ADMIN_PAY.Pay;
AVG( ) ,
. COUNT( ) ,
. COUNT(*)
. MAX( )
, .
MIN( ) ,
. SUM( )
, .
24

33. :
VFP, MS SQL Server, Access:
SELECT
RTRIM(Name)+'
'+RTRIM(Lastname)+'
'+Surname,
Staff.T_number, SUM(Sum_pay) FROM Staff, Pay WHERE (Staff.T_number =
Pay.T_number) GROUP BY Staff.T_number, RTRIM(Name) + ' ' +
RTRIM(Lastname)+' '+Surname
Oracle:
SELECT
RTRIM(Name)+'
'+RTRIM(Lastname)+'
'+Surname,
Staff.T_number,
SUM(Sum_pay)
FROM
ADMIN_PAY.Staff,
ADMIN_PAY.Pay WHERE (Staff.T_number = Pay.T_number) GROUP BY
Staff.T_number, RTRIM(Name) + ' ' + RTRIM(Lastname)+' '+Surname;
GROUP BY .

. , ,
,
.
GROUP BY
,
. GROUP BY,

.
HAVING ,
, .
HAVING
.
34. ,
10000:
VFP:
SELECT Name, Staff.T_number, AVG(Sum_pay) FROM Staff, Pay
WHERE (Staff.T_number = Pay.T_number) AND (Pay_day BETWEEN
CTOD(01.01.2002)
AND
CTOD(31.12.2002)
)
GROUP
BY
Staff.T_number, Name HAVING AVG(Sum_pay)>10000
MS SQL Server:
SELECT Name, Staff.T_number, AVG(Sum_pay) FROM Staff, Pay
WHERE (Staff.T_number = Pay.T_number) AND (Pay_day BETWEEN '01JAN-2002' AND '31-DEC-2002' ) GROUP BY Staff.T_number, Name
HAVING AVG(Sum_pay)>10000
Access:
SELECT Name, Staff.T_number, AVG(Sum_pay) FROM Staff, Pay
WHERE (Staff.T_number = Pay.T_number) AND (Pay_day BETWEEN
25

#01.01.2002# AND #31.12.2002# ) GROUP BY Staff.T_number, Name


HAVING AVG(Sum_pay)>10000
Oracle:
SELECT
Name,
Staff.T_number,
AVG(Sum_pay)
FROM
ADMIN_PAY.Staff, ADMIN_PAY.Pay WHERE (Staff.T_number =
Pay.T_number) AND (Pay_day BETWEEN '01-JAN-2002' AND '31-DEC2002' ) GROUP BY Staff.T_number, Name HAVING AVG(Sum_pay)>10000;
35. ,
5 :
VFP, MS SQL Server, Access:
SELECT Post, Count(T_number) FROM Staff GROUP BY Post HAVING
Count(T_number)<5
Oracle:
SELECT Post, Count(T_number) FROM ADMIN_PAY.Staff GROUP BY
Post HAVING Count(T_number)<5;
36.
(. 13):
VFP, MS SQL Server, Access:
SELECT Min(Date_input), Max(Date_input) FROM Staff
Oracle:
SELECT Min(Date_input), Max(Date_input) FROM ADMIN_PAY.Staff;
Min_date_input
12.11.1979

Max_date_input
18.11.2003

. 13.

.
37. ,
, ,
Itog:
MS SQL Server:
SELECT Name+Lastname+Surname AS [...], Staff.T_number,
SUM(Sum_pay) AS Itog FROM Staff, Pay WHERE (Staff.T_number =
Pay.T_number) GROUP BY Staff.T_number, Name+Lastname+Surname
Oracle:
SELECT Name+Lastname+Surname AS "...", Staff.T_number,
SUM(Sum_pay) AS Itog FROM ADMIN_PAY.Staff, ADMIN_PAY.Pay
WHERE (Staff.T_number = Pay.T_number) Group by Staff.T_number,
Name+Lastname+Surname;

26

AS ,
, .
38. , ,
,
, Sum_With_Nalog:
VFP, MS SQL Server, Access:
SELECT Staff.T_number, Name, Surname, Pay_day, Sum_pay, (Sum_payItem_sum) AS Sum_With_Nalog FROM Staff INNER JOIN Pay INNER JOIN
Items_pay ON Pay.Code_pay = Items_pay.Code_pay ON Staff.T_number =
Pay.T_number WHERE Item_pay = ' '
Oracle:
SELECT Staff.T_number, Name, Surname, Pay_day, Sum_pay, (Sum_payItem_sum) AS Sum_With_Nalog FROM ADMIN_PAY.Staff INNER JOIN
ADMIN_PAY.Pay INNER JOIN ADMIN_PAY.Items_pay ON Pay.Code_pay
= Items_pay.Code_pay ON Staff.T_number = Pay.T_number WHERE
Item_pay = ' ';
,
.
39. , ,
FIO (. 14):
VFP, MS SQL Server, Access:
SELECT (RTRIM(Surname) + ' ' + RTRIM(Name) + ' '+ Lastname) AS
FIO FROM Staff
Oracle:
SELECT (RTRIM(Surname) + ' ' + RTRIM(Name) + ' '+ Lastname) AS
FIO FROM ADMIN_PAY.Staff;
FIO






. 14.

40. , ,
FIO_Post:
VFP, MS SQL Server, Access:
27

SELECT (RTRIM(Surname) + ' ' + RTRIM(Name) + ' ' +


RTRIM(Lastname) + ' ' + Post) AS FIO_Post FROM Staff
Oracle:
SELECT (RTRIM(Surname) + ' ' + RTRIM(Name) + ' ' +
RTRIM(Lastname) + ' ' + Post) AS FIO_Post FROM
ADMIN_PAY.Staff;
.
41. ,
:
VFP:
Local Perem_B, Perem_E
&&
Perem_B=GOMONTH(Date(),-1) &&
Perem_E = Date()
&&
SELECT Name, Lastname, Surname FROM Staff WHERE Date_Input
BETWEEN Perem_B AND Perem_E
MS SQL Server:
--
Declare @Perem_B DateTime, @Perem_E DateTime
--
SET @Perem_B=DATEADD ( month , -1, getdate())
--
SET @Perem_E = GetDate( )
SELECT Name, Lastname, Surname FROM Staff WHERE Date_Input
BETWEEN @Perem_B AND @Perem_E
Oracle:
SET SERVEROUTPUT ON;
Declare
Perem_B Date;
Perem_E Date;
Name_ ADMIN_PAY.Staff.Name%TYPE;
Lastname_ ADMIN_PAY.Staff.Lastname%TYPE;
Surname_ ADMIN_PAY.Staff.Surname%TYPE;
BEGIN
Perem_B:= ADD_MONTHS(Sysdate,-1) ;
Perem_E:= Sysdate;
DBMS_OUTPUT.PUT_LINE(Perem_B||' '||Perem_E);

28

SELECT Name, Lastname, Surname INTO Name_, Lastname_, Surname_


FROM ADMIN_PAY.Staff WHERE Date_Input BETWEEN Perem_B AND
Perem_E;
END;
42. ,
(. 15):
VFP:
Local Perem
&&
Perem = 45
SELECT Name, Lastname, Surname FROM Staff WHERE
((Day(Birthday)+Month(Birthday)*30.5)/365.25-Year(Birthday)+Year(Date()))
< Perem
MS SQL Server:
Declare @Perem Int
--
SET @Perem= 45
SELECT Name, Lastname, Surname FROM Staff WHERE CAST(
(getdate( )-Birthday) AS INT) < @Perem
Oracle:
--
Declare
Perem number(2);
Name_ ADMIN_PAY.Staff.Name%TYPE;
Lastname_ ADMIN_PAY.Staff.Lastname%TYPE;
Surname_ ADMIN_PAY.Staff.Surname%TYPE;
BEGIN
--
Perem:= 45;
SELECT Name, Lastname, Surname INTO Name_, Lastname_, Surname_
FROM ADMIN_PAY.Staff WHERE trunc((Sysdate-Birthday)/365.25) <
Perem;
END;
Name

Lastname

Surname

. 15.

29

43. ,
:
VFP:
Local Perem
&&
Perem =
SET ANSI OFF
&&
SELECT Name, Lastname, Surname FROM Staff WHERE Surname =
Perem
MS SQL Server:
Declare @Perem VarChar(10)
--
SET @Perem= ''
SELECT Name, Lastname, Surname FROM Staff WHERE Surname LIKE
RTRIM(@Perem)+'%'
Oracle:
Declare
Perem VarChar2(10);
Surname_ ADMIN_PAY.Staff.Surname%TYPE;
--
BEGIN
Perem:= '';
SELECT Surname INTO Surname_ FROM ADMIN_PAY.Staff WHERE
Surname LIKE RTRIM(Perem)+'%';
END;
.
44. , ,
,
:
VFP, MS SQL Server, Access:
SELECT a.T_number, Name, Surname, Pay_day, Sum_pay, (Sum_payItem_sum) FROM Staff a, Pay b, Items_pay c WHERE b.Code_pay =
c.Code_pay AND a.T_number = b.T_number AND Item_pay = '
'
Oracle:
SELECT a.T_number, Name, Surname, Pay_day, Sum_pay, (Sum_payItem_sum)
FROM
ADMIN_PAY.Staff
a,
ADMIN_PAY.Pay
b,
ADMIN_PAY.Items_pay c WHERE b.Code_pay = c.Code_pay AND
a.T_number = b.T_number AND Item_pay = ' ';

30



.
45. (.
16):
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, d.T_number, SUM(Sum_pay) FROM
Staff d, Pay f WHERE (d.T_number = f.T_number) GROUP BY d.T_number
Oracle:
SELECT
Surname,
d.T_number,
SUM(Sum_pay)
FROM
ADMIN_PAY.Staff d, ADMIN_PAY.Pay f WHERE (d.T_number =
f.T_number) GROUP BY d.T_number, Surname;
Name

Lastname

Surname

T_number
1
2
3
4

Sum_sum_pay
19607.00
5732.00
7595.00
2456.00

. 16.

46. ,
: , , ,
:
VFP, MS SQL Server, Access:
SELECT Name, Lastname, Surname, b.Code_pay FROM Staff a, Pay b,
Items_pay c WHERE b.Code_pay = c.Code_pay AND a.T_number =
b.T_number AND Item_pay IN('', ' ', '')
Oracle:
SELECT
Name,
Lastname,
Surname,
b.Code_pay
FROM
ADMIN_PAY.Staff a, ADMIN_PAY.Pay b, ADMIN_PAY.Items_pay c
WHERE b.Code_pay = c.Code_pay AND a.T_number = b.T_number AND
Item_pay IN('', ' ', '');
.
47.

Temp1:
VFP:
SELECT Name, Lastname, Surname, Sum_pay, Pay_Day FROM Staff, Pay
INTO CURSOR Temp1 WHERE (Staff.T_number = Pay.T_number) AND
Surname = AND Name =

31

MS SQL Server:
Declare TEMP1 CURSOR FOR SELECT Name, Lastname, Surname,
Sum_pay, Pay_Day FROM Staff, Pay WHERE (Staff.T_number =
Pay.T_number) AND Surname = '' AND Name = ''
Oracle ( ):
SET SERVEROUTPUT ON
DECLARE
Name1 ADMIN_PAY.Staff.Name%TYPE;
Lastname1 ADMIN_PAY.Staff.Lastname%TYPE;
Surname1 ADMIN_PAY.Staff.Surname%TYPE;
Sum_pay1 ADMIN_PAY.Pay.Sum_pay%TYPE;
Pay_Day1 ADMIN_PAY.Pay.Pay_Day%TYPE;
CURSOR TEMP1 IS SELECT Name, Lastname, Surname, Sum_pay,
Pay_Day
FROM
ADMIN_PAY.Staff,
ADMIN_PAY.Pay
WHERE
(Staff.T_number = Pay.T_number) AND Surname = '' AND Name =
'';
BEGIN
OPEN TEMP1;
WHILE TEMP1%found LOOP
FETCH TEMP1 INTO Name1, Lastname1, Surname1, Sum_pay1,
Pay_Day1;
DBMS_OUTPUT.PUT_LINE(Name1||' '|| Lastname1||' '||Surname1||' '||
Sum_pay1||' '|| Pay_Day1);
END LOOP;
CLOSE TEMP1;
END;

,
( INTO DBF INTO TABLE)
, ,
.
INTO CURSOR
( Temp1),
.
48. 1254
Temp2 (. 17):
VFP:
SELECT * FROM Staff INTO CURSOR Temp2 WHERE T_number
BETWEEN 12 AND 54
32

MS SQL Server:
Declare Temp2 CURSOR FOR SELECT * FROM Staff WHERE
T_number BETWEEN 12 AND 54
Oracle:
DECLARE
CURSOR TEMP1 IS SELECT * FROM ADMIN_PAY.Staff WHERE
T_number BETWEEN 12 AND 54;
BEGIN
Null;
END;
T_number
15

Surname

Name

Lastname

Birthday
12.03.1960

Date_input
12.11.1979

. 17.

.
49. ,
:
VFP, MS SQL Server, Access:
SELECT DISTINCT Name, Lastname, Surname FROM Staff, Pay WHERE
Staff.T_number = Pay.T_number AND EXISTS(SELECT * FROM Items_pay
WHERE Items_pay.Code_pay = Pay.Code_pay AND Item_pay='')
Oracle:
SELECT
DISTINCT
Name,
Lastname,
Surname
FROM
ADMIN_PAY.Staff, ADMIN_PAY.Pay WHERE Staff.T_number =
Pay.T_number AND EXISTS(SELECT * FROM ADMIN_PAY.Items_pay
WHERE Items_pay.Code_pay = Pay.Code_pay AND Item_pay='');
EXISTS( ) , ,
. : ,
. , ,
,
.
50. ,
:
VFP, MS SQL Server, Access:
SELECT Surname, Name, Lastname FROM Staff WHERE NOT
EXISTS(SELECT * FROM Pay WHERE Staff.T_number = Pay.T_number)

33

Oracle:
SELECT Surname, Name, Lastname FROM ADMIN_PAY.Staff WHERE
NOT EXISTS(SELECT * FROM ADMIN_PAY.Pay WHERE Staff.T_number
= Pay.T_number);
51. ,
3000 . (. 18):
VFP, MS SQL Server, Access:
SELECT Surname, Name, Lastname FROM Staff WHERE
EXISTS(SELECT * FROM Pay WHERE Staff.T_number = Pay.T_number
AND Sum_pay >=3000)
Oracle:
SELECT Surname, Name, Lastname FROM ADMIN_PAY.Staff WHERE
EXISTS(SELECT * FROM ADMIN_PAY.Pay WHERE Staff.T_number =
Pay.T_number AND Sum_pay >=3000);
Surname

Name

Lastname

. 18.

.
52.
, (. 19):
VFP, MS SQL Server, Access:
SELECT Surname, Name, Lastname, Sum_pay, Pay_Day FROM Staff
INNER JOIN PAY ON Staff.T_number = Pay.T_number WHERE
Pay.Sum_pay>(SELECT AVG(Sum_pay) FROM Pay)
Oracle:
SELECT Surname, Name, Lastname, Sum_pay, Pay_Day FROM
ADMIN_PAY.Staff INNER JOIN ADMIN_PAY.PAY ON Staff.T_number =
Pay.T_number WHERE Pay.Sum_pay>(SELECT AVG(Sum_pay) FROM
ADMIN_PAY.Pay);
Surname

Name

Lastname

Sum_pay
12542.00
4521.00
4511.00

Pay_day
01.03.2003
01.02.2003
01.01.2003

. 19.

34

Update.
53. ,
:
VFP:
SET ANSI OFF
UPDATE Staff SET Type_post = WHERE Post =
MS SQL Server:
UPDATE Staff SET Type_post = '' WHERE Post LIKE '%'
Oracle:
UPDATE ADMIN_PAY.Staff SET Type_post = '' WHERE Post LIKE
'%';
UPDATE
.
, ,
.
WHERE ,
. SET ,
, .
54. .,
, 20 60 :
VFP:
UPDATE Staff SET Type_post = ., Post = WHERE (Date()Date_Input)/365.25>20 AND (Date()-Birthday)/365.25>60
MS SQL Server:
UPDATE Staff SET Type_post = '.', Post = ' ' WHERE
CAST(DATEDIFF(Year,Date_Input,GetDate())
AS
INT)>20
AND
CAST(DATEDIFF(Year,Birthday,GetDate()) AS INT)>60
Oracle:
UPDATE ADMIN_PAY.Staff SET Type_post = '.', Post = ' ' WHERE
(Sysdate-Date_Input)/365.25>20 AND (Sysdate- Birthday)/365.25>60;
55. Post ,
:
VFP:
UPDATE Staff SET Post = WHERE ALLTRIM(Post) =
MS SQL Server:
UPDATE Staff SET Post = ' ' WHERE RTRIM(Post) = '' OR
Post IS Null
35

Oracle:
UPDATE ADMIN_PAY.Staff SET Post = ' ' WHERE
RTRIM(Post) = '' OR Post IS Null;
Insert.
56. , ,
1,
:
VFP ( ):
SELECT MAX(T_number) AS Max_ FROM Staff INTO CURSOR Temp
INSERT INTO Staff(T_number, Post)VALUES(Temp.Max_+1,
)
MS SQL Server ( c ,
IDENTITY(1,1) ):
INSERT INTO Staff(Post)VALUES(' ')
MS SQL Server( ):
Declare @max bigint
SET @max = (SELECT MAX(T_number) FROM Staff)
SET @max = ISNULL(@max, 0)
INSERT INTO Staff(T_number, Post)VALUES(@max+1, ' ')
Oracle (
SEQUENCE ):
INSERT
INTO
ADMIN_PAY.Staff(T_number,
Post)VALUES
(ADMIN_PAY.ID_STAFF_SEQ.NextVal, ' ');
Oracle (
):
DECLARE
Max_ int;
BEGIN
SELECT MAX(T_number) INTO Max_ FROM ADMIN_PAY.Staff;
IF Max_ IS NULL THEN
Max_:=0;
END IF;
INSERT INTO ADMIN_PAY.Staff(T_number, Post)VALUES (Max_+1,
' ');
END;

SELECT ,

,
36

(
).
INSERT .
INTO ,
( ), VALUES
. ,
. ,
, NULL
( ).

.
57. Pay , ,
1, =23,
= , = 5000:
VFP ( ):
SELECT MAX(Code_pay) AS Max_ FROM Pay INTO CURSOR Temp
INSERT INTO Pay(T_number, Code_pay, Pay_day, Sum_pay) VALUES(23,
Temp.Max_+1, Date(), 5000)
MS SQL Server ( c ,
IDENTITY(1,1) ):
INSERT INTO Pay(T_number, Pay_day, Sum_pay) VALUES(23,
GetDate(), 5000)
MS SQL Server( ):
Declare @max bigint
SET @max = (SELECT MAX(Code_pay) FROM Pay)
SET @max = ISNULL(@max, 0)
INSERT INTO Pay(T_number, Code_pay, Pay_day, Sum_pay)
VALUES(23, @max+1, GetDate(), 5000)
Oracle (
SEQUENCE ):
INSERT INTO ADMIN_PAY.Pay(T_number, Code_pay, Pay_day,
Sum_pay) VALUES(23, ADMIN_PAY.ID_PAY_SEQ.NextVal, SysDate,
5000);
Oracle (
):
DECLARE
Max_ int;
BEGIN
SELECT MAX(Code_pay) INTO Max_ FROM ADMIN_PAY.Pay;
37

if Max_ IS NULL then


Max_:=0;
END IF;
INSERT INTO ADMIN_PAY.Pay(T_number,
Sum_pay) VALUES(23, Max_+1, SysDate, 5000);
END;

Code_pay,

Pay_day,

INSERT , Staff
T_number=23 .
58. Items_pay , ,
45, = , =
1500 . (. 20):
VFP, MS SQL Server, Access ( Code_Items
):
INSERT INTO Items_pay(Code_pay, Item_pay, Item_sum) VALUES(45,
'', 1500)
Oracle ( Code_Items
SEQUENCE):
INSERT INTO ADMIN_PAY.Items_pay(Code_pay, Item_pay, Item_sum,
Code_Items)
VALUES(45,
'',
1500,
ADMIN_PAY.ID_ITEM_SEQ.NextVal);
INSERT , Pay
Code_pay=45 .
Delete.
59. ,
80 (. 20):
Code_pay
1
1
1
2
2
2
3
3
10
10
10
10
45

Item_pay

Item_sum
1457.00
4512.00
145.00
4656.00
-415.00
326.00
1654.00
1213.00
-154.00
1456.00
1245.00
-452.00
1500.00

. 20.
Insert
38

VFP:
DELETE FROM Staff WHERE (Date()-Birthday)>80
MS SQL Server:
DELETE FROM Staff WHERE CAST( DATEDIFF( Year, Birthday,
GetDate()) AS INT) >80
Oracle:
DELETE
FROM
ADMIN_PAY.Staff
WHERE
(SysdateBirthday)/365.25>80;
DELETE
. FROM ,
, . WHERE
, .

.
60. ( Items_pay) ,
= :
VFP, MS SQL Server, Access:
DELETE FROM Items_pay WHERE Item_pay=' '
Oracle:
DELETE FROM ADMIN_PAY.Items_pay WHERE Item_pay='
';
61. ,
0:
VFP, MS SQL Server, Access:
DELETE FROM Pay WHERE T_number = 0 AND Sum_pay = 0
Oracle:
DELETE FROM ADMIN_PAY.Pay WHERE T_number = 0 AND
Sum_pay = 0;

39

2. SQL
2.1.
21
.

DB_BOOKS , 711,
, .
Purchases

Books

Authors

Code_book
Date_order
Code_delivery
Type_purchase
Cost
Amount
Code_purchase

Code_book
Title_book
Code_author
Pages
Code_publish

Code_author
Name_author
Birthday

Deliveries

Publishing_house

Code_delivery
Name_delivery
Name_company
Address
Phone
INN

Code_publish
Publish
City

. 21.


-- :
1. Books.Code_book - Purchases.Code_book;
2. Deliveries.Code_delivery - Purchases.Code_delivery;
3. Authors.Code_author - Books.Code_author;
4. Publising_house.Code_publish - Books.Code_publish.
7
( Purchases)

Code_book
Date_order
Code_delivery
Type_purchase
Cost
Amount
Code_purchase


Integer
Datetime
Integer
Bit
Money
Integer
Integer





(/ )


40

8
( Books)

Code_book
Title_book
Code_author
Pages
Code_publish


Integer
Char
Integer
Integer
Integer

( Authors)

Code_author
Name_ author
Birthday


Integer
Char
Datetime



, ,

10
( Deliveries)

Code_delivery
Name_delivery
Name_company
Address
Phone
INN


Integer
Char
Char
Char
Numeric
Char



, ., .
-

11
( Publishing_house)

Code_publish
Publish
City


Integer
Char
Char

2.2.

.
1. Books
( Code_book).
2. Books ,
( Code_book, Title_book Pages),
41

( Title_book ) Pages (
).
3. Deliveries (
Name_delivery, Phone INN), INN (
).
.
4. Deliveries ,
: Name_delivery, INN, Phone,
Address, Code_delivery.
5. Publishing_house ,
: Publish, City,
Code_publish.
.
6. Books
( Title_book Pages), Authors
( Name_ author).
7. Books (
Title_book Pages), Deliveries
( Name_delivery).
8. Books (
Title_book Pages), Publishing_house
( Publish City).
.
9. ( Deliveries)
, ( Name_company, Phone INN),
( Name_company) .
10. Books
( Title_book Pages), Authors
( Name_ author),
.
11. Authors , ,
( Name_ author), .
.
12. ( Publish)
Publishing_house, (
City).

42

13. ( Title_book) Books,


, ( Publish Publishing_house).
(Between).
14. , , ( Name_author)
Authors, ( Birthday)
01.01.1840 01.06.1860.
15. ( Title_book Books)
( Amount Purchases),
12.03.2003 15.06.2003 (
Date_order Purchases).
16. ( Title_book)
( Pages) Books,
200 300 ( Pages).
17. , , (
Name_author) Authors,
( Name_author).
(In).
18. ( Title_book Books)
( Amount Purchases),
3, 7, 9, 11 (
Code_delivery Purchases).
19. ( Title_book) Books,
: -, ,
( Publish Publishing_house).
20. ( Title_book) Books,
: ..,
.., .. ( Name_author Authors).
Like.
21. ( Name_author) Authors,
.
22. ( Publish)
Publishing_house, .
23. ( Name_company)
Deliveries, .
.
24. ( Code_delivery),
( Date_order) ( Title_book),
43

( Amount) 100 ( Cost)


200 500 .
25. ( Code_author), (
Name_author), ( Title_book),
( Code_Publish) 10 25
( Pages) 120.
26. ( Publish)
Publishing_house, , (
Title_book) ( City)
.
( ,
JOIN).
27.

-
(
Name_company) ( Title_book),
01.01.2002 31.12.2003 ( Date_order).
28. ( Name_author),
( Publish).
29. ( Name_company),
( Publish).
30. ( Name_author) (
Title_book),
( Name_company).
.
31.
( Amount Cost) ( Title_book)
.
32.
( Cost Pages) (
Title_book).
33.
( Birthday) (
Name_author).

.
34. ( Cost),
( Name_company).
35. (
Purchases), 01.01.2003
01.02.2003 ( Date_order).
44

36. ( Cost)
( Amount)
, (
Name_author).
37. ( Purchases),
( Title_book)
( Cost Amount).
38. ( Purchases),
( Title_book)
( Cost Amount).
.
39. ( Title_book),
( Amount Cost),
Itogo, 01.01.2002
01.06.2002 ( Date_order).
40.
( Cost Pages),
One_page, ( Title_book).
41. ( Cost)
Sum_cost,
( Name_company).
.
42. ( Purchases)
( Date_order).
43. ( Name_author),
(
Birthday).
44. ( Title_book), ,
(
Amount).
.
45.

-
(
Name_company) ( Title_book), .
46. ( Name_author),
, , (
Publish).
47. ( Name_company),
150 . ( Cost).

45

.
48. ( Title_book)
( Pages)
Temp1.
49.

-
(
Name_company) Temp2.
50. ( Name_author)
Temp3.
.
51. ( Title_book),
( Pages)
.
52. ( Name_author),
(
Birthday).
53. ( Title_book),
( Pages) ,
.
.
54. ( Publish),
( Type_Purchase).
55. ( Name_author),
Books.
56. ( Title_book),
( Name_company).
Update.
57. Books Pages 300,
( Code_author) =56 ( Title_book)
=.
58. Deliveries Address
, .
59. Purchases ( Cost) 20 ,
(
Date_order).
Insert.
60. Purchases , ,
( Code_purchase) ,
( Type_purchase) .
46

61. Books ,
( Code_book),
, (
Title_book) . . .
62. Publish_house ,
( Code_publish),
,
( City),
( Publish).
Delete.
63. Purchases ,
( Amount) = 0.
64. Authors ,
Name_Author.
65. Deliveries ,
( INN ).
2.3.
22
.

DB_STUDY , 1216,
, .
Students
Code_stud
Surname
Name
Lastname
Birthday
Phone
Code_group

Progress
Code_stud
Code_subject
Code_lector
Date_exam
Estimate
Code_progress

Subjects
Code_subject
Name_subject
Count_hours

Lectors
Code_lector
Name_lector
Science
Post
Date_

Groups
Code_group
Name_group
Num_course
Name_speciality

. 22.
47


-- :
1. Groups.Code_group - Students.Code_group;
2. Students.Code_stud - Progress.Code_stud;
3. Subjects.Code_subject - Progress.Code_subject;
4. Lectors.Code_lector - Progress.Code_lector.
12
( Groups)

Code_group
Name_group
Num_course
Name_speciality


Integer
Character
Integer
Character

13
( Students)

Code_stud
Surname
Name
Lastname
Code_group
Birthday
Phone


Character
Character
Character
Character
Integer
Date
Numeric

14
( Subjects)

Code_subject
Name_subject
Count_hours


Integer
Character
Integer

15
( Progress)

Code_stud
Code_subject
Code_lector
Date_exam
Estimate
Code_progress


Character
Integer
Integer
Date
Integer
Integer


48

16
( Lectors)

Code_lector
Name_lector
Science
Post
Date_


Integer
Character
Character
Character
Date



, ,

2.4.

.
66. Students
( Code_stud).
67. , , (
Name_lector), ( Post) ( Science)
Lectors,
( Post)
( Science).
68. Groups (
Name_group, Name_course)

Name_course .
.
69. Students
, :
Code_group, Name, Surname, Lastname, Phone, Birthday.
70. Subjects ,
: Name_subject, Code_subject.
.
71. ( Surname), ( Name),
( Lastname) Students
( Name_group) Groups, .
72. ( Date_exam) Progress
, , ( Name_lector)
Lectors, .
73. ( Date_exam) Progress
( Name_subject) Subjects,
.

49

.
74. ( Name_lector)
Lectors - , ..
Science .
75. ( Surname, Name, Lastname)
Students ( Name_group) Groups,
.
76. ( Name_subject)
Subjects, .
.
77. ( Name_lector)
Lectors ( Post),
, .. Science ....
78. ( Name_group) Groups,
(
Name_speciality).
79. Subjects,
( Name_subject).
(Between).
80. ( Date_exam) Progress
( Name_subject) Subjects,
01.01.2003 01.02.2003 (
Date_exam).
81. ( Name_lector)
Lectors ( Post),
12.03.2000 15.06.2000 ( Date_).
82. ( Surname, Name, Lastname)
( Phone) Students,
220000 226666 ( Phone).
83. ( Name_subject)
Subjects,
( Name_subject).
(In).
84. (
Name_group Name_speciality Groups),
-12-02, -1403, -21-03, -12-02 ( Code_stud
Students).

50

85. ( Name_lector)
Lectors ( Post),
: ..., ..., ... ( Science).
86. ( Surname, Name, Lastname)
Students,
: 5, 8, 12, 25 ( Code_subject).
Like.
87. ( Name_subject)
Subjects, .
88. ( Surname, Name, Lastname)
( Birthday) Students,
( Surname).
89. ( Name_group) Groups,
0 ().
.
90. ( Surname, Name, Code_group)
Students, (
Name_subject Subjects) .
91. ( Name_lector)
Lectors, (
Code_subject Progress) 5 12 01.01.2003
01.02.2003 ( Date_exam Progress).
92. ( Name_group) (
Num_course) Groups,
01.01.1976 01.01.1978 ( Birthday
Students) 10 150 ( Code_stud
Students).
( ,
JOIN).
93. ( Name_subject
Subjects) ( Name_lector
Lectors), .
94. ( Surname, Name
Students) ( Num_course Groups),
-31 ( Name_group).
95. ( Name_lector
Lectors),
10, 12, 15 ( Code_group Students).

51

96. ( Name_subject
Subjects) ( Name_lector
Lectors),
15.01.2003 16.02.2003 ( Date_exam
Progress).
.
97. (Name_lector),
( Science) ( Date_
Lectors).
98. ( Surname, Name, Lastname)
( Birthday Students).
99. ( Surname, Name, Lastname
Students) , ,
( Num_course
Groups).

.
100. ( Name_group Groups)
(
Students).
101. ( Estimate
Progress)
( Surname, Name Students)
05.01.2003 25.01.2003 ( Date_exam
Progress).
102. ( Surname, Name
Students)
( Estimate Progress).
103. ( Lectors)
( Date_).
.
104. ( Name_group Groups)
(
Students), Count_Students.
105. ( Estimate
Progress) ,
Avg_estimate, ( Surname, Name
Students) 05.01.2003 25.01.2003 (
Date_exam Progress).
52

106. (Name_lector),
( Science) ( Date_
Lectors), Old_years.
.
107. ( Surname, Name, Lastname)
( Phone) Students,
, Phone_begin
Phone_end.
, Phone_begin = 125478, Phone_end = 352456.
108. (
Birthday) Students, ,
Birthday_begin Birthday_end.
, Birthday_begin = 12.03.1978, Birthday_end =
12.03.1980.
109. ( Surname, Name, Lastname)
( Name_group) (
Code_group), ,
Group_begin Group_end.
, Group_begin = 12, Group_end = 35.
.
110. ( Code_stud) ( Surname,
Name), ( Name_group, Code_group
Groups), Students A,
Groups B.
111. ( Surname, Name),
( Name_subject, Code_subject Subjects),
, ( Estimate),
Students A, Progress
B, Subjects
C.
112. ( Surname, Name),
( Name_lector, Code_lector Lectors),
, (
Estimate), Students A,
Progress B, Lectors
C.
.
113. (
Progress) (
53

Surname, Name Students)


Temp1.
114. ( Name_group,
Name_speciality Groups), = 2 (
Num_course), Temp2.
115. ( Name_subject
Subjects) Temp3.
.
116. ( Lectors),

( Date_).
117. (
Progress) ( Surname, Name Students),
Progress (
Date_exam ).
118. ( Name_group),
25.
.
119. ( Surname, Name, Lastname
Students), (
Progress).
120. ( Surname, Name, Lastname
Students), (
Progress).
121. ( Surname, Name, Lastname
Students), "" (
Progress).
Update.
122. ( Num_course)
Groups,
.
123. Students Lastname
, .
124. Subjects Name_subject
,
.

54

Insert.
125. Student , ,
( Code_stud) ,
= ( Surname, Name, LastName).
126. Progress ,
( Code_stud) 45, (
Code_subject) 12, ( Code_lector) 11,
( Date_exam) 12.03.2003.
127. Lectors ,
( Code_lector),
,
( Name_lector) ,
( Science) ....
Delete.
128. Students ,
35, 15, 19 ( Code_group).
129. Subjects ,
Name_subject .
130. Progress ,
( Date_exam ).

55

3.
,
,
.
SQL
(5 10) ,
.

.

1
2
3
4
5
6
7
8
9
10


1
2
3
4
5
66
67
68
69
70

6
7
8
9
10
71
72
73
74
75

11
12
13
14
15
76
77
78
79
80

16
17
18
19
20
81
82
83
84
85

21
22
23
24
25
86
87
88
89
90

26 31
27 32
28 33
29 34
30 35
91 96
92 97
93 98
94 99
95 100

56

36
37
38
39
40
101
102
103
104
105

41
42
43
44
45
106
107
108
109
110

46
47
48
49
50
111
112
113
114
115

51
52
53
54
55
116
117
118
119
120

56
57
58
59
60
121
122
123
124
125

61
62
63
64
65
126
127
128
129
130


1. . . SQL / . . , . . ,
.. . .: , 2002. 176 .
2. . SQL. SQL92, SQL99 SQLJ..: , 2001. 644 .
3. . SQL. . .: , 2001.354 .
4. . SQL. .: , 1993.420 .
5. . SQL. .: , 1997. 291 .
6. . SQL. 3- . : , 2003.896 .
7. ., . SQL: .:
BHV, McGrawHill Companies, 2001.816 .
8. ., . SQL: . :
BHV, 1998. 608 .
9. . SQL: Structured Query Language. ..:
, 2001.416 .
10. Oracle 10g: PL/SQL Packages and Types Reference. .
. 2007. :
http://www.oracle.com/pls/db102/to_pdf?pathname=appdev.102%2Fb14258.pdf&remark=po
rtal+%28Books%29. . . . . Oracle.
11. Oracle 10g: PL/SQL User's Guide and Reference. . .
2007. :
http://www.oracle.com/pls/db102/to_pdf?pathname=appdev.102%2Fb14261.pdf&remark=po
rtal+%28Books%29. . . . . Oracle.
12. . SQL. / , ,
. .: . , 2002.746 .
13. .. (SQL). .: , 1994.
80 .
14. . SQL. . .: , 2001. 192 .
15. . : PL/SQL Oracle. . . 2007.
: http://www.firststeps.ru/sql/oracle/oracle1.html,
http://www.firststeps.ru/sql/oracle/oracle2.html,
http://www.firststeps.ru/sql/oracle/oracle3.html. . . . . .
16. . . SQL99. . .:
, 2002.816 .
17. .. , .. SQL. .: , 1998. 400 .
18. . SQL . ., 2001. 368 .

57

SQL MS SQL SERVER, ORACLE, VFP ACCESS:



***
..

***
__________
6090 1/16.


... ___, .-.. ___
100 . ___


644099, , . ., 10

644099, , . ., 10