Professional Documents
Culture Documents
SQL Server
SQL Server
7.0 . Package .
% Database
. IBM SEQUEL Query ) (
. Query
) Administrating( ) Sequrity( Database
SQL . Microsoft SQL
Server 2000 Transact SQL TSQL SQL Server 2000 .
: Edition SQL Server 2000 Personal Client ) Windows 98
Proffessional Windows XP Home Edition Windows XP Proffessional Windows ME Windows 2000
(Edition Windows 98 Windows ME Package
. Proffessional Windows 2000 Windows XP
Proffessional . Server 2000 Enterprise Edition SQL :
Server Window 2K Server Windows Server 2003
:CREATE TABLE
. sql .
.
.
) (ROW ) (COLUMN .
. .
: .
.
: // -
: // -
. . )(
. string integer
date .
. :
"CREATE TABLE "table_name
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
) ...
:
CREATE TABLE customer
(First_Name char(50),
Last_Name char(50),
Address char(50),
City char(50),
Country char(25),
)Birth_Date date
: DROP TABLE
SQL .
.
"DROP TABLE "table_name
:
: TRUBCATE TABLE .
.
: INSERT INTO .
) ( .
.
)INSERT INTO "table_name" ("column1", "column2", ...
)VALUES ("value1", "value2", ...
.
Table Store_Information
)store_name char(50
float
Sales
datetime
Date
)( . :
. $ .
)INSERT INTO Store_Information (store_name, Sales, Date
)'VALUES ('Los Angeles', 900, 'Jan-10-1999
.
SELECT .
.
)INSERT INTO "table_name" ("column1", "column2", ...
SELECT "column1", "column2", ...
"FROM "table1
. select where ,
Group by , Having .
:
)INSERT INTO Store_Information (store_name, Sales, Date
SELECT store_name, Sales, Date
FROM Sales_Information
WHERE Year(Date) = 1998
.
.
:
WHERE to_char(date,'yyyy')=1998
: UPDATE .
UPDATE .
"UPDATE "table_name
]SET "column_1" = [new value
}WHERE {condition
: .
Table Store_Information
San Diego
Boston
01/08/1999 $
. .
UPDATE Store_Information
SET Sales = 500
"WHERE store_name = "Los Angeles
"AND Date = "Jan-08-1999
.
Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
$250 Jan-07-1999
San Diego
Boston
: UPDATE .
"DELETE FROM "table_name
}WHERE {condition
: .
Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
$250 Jan-07-1999
San Diego
Boston
.
.
DELETE FROM Store_Information
"WHERE store_name = "Los Angeles
:
Table Store_Information
store_name Sales Date
San Diego
$250 Jan-07-1999
Boston
$700 Jan-08-1999
Sql server .
. ) ( Oracle Access
. SQL
.
. .
Select
SELECT "column_name" FROM "table_name "
Distinct
SELECT DISTINCT "column_name "
FROM "table_name "
Where
SELECT "column_name "
FROM "table_name "
WHERE "condition "
And/Or
SELECT "column_name "
FROM "table_name "
WHERE "simple condition "
]}AND|OR] "simple condition +{"
In
SELECT "column_name "
FROM "table_name "
WHERE "column_name" IN ('value1', 'value2 (... ,'
Between
SELECT "column_name "
FROM "table_name "
WHERE "column_name" BETWEEN 'value1' AND 'value2 '
Like
SELECT "column_name "
FROM "table_name "
WHERE "column_name" LIKE {PATTERN {
Order By
SELECT "column_name "
: SELECT
.
.
SELECT "column_name" FROM "table_name" :
: :
Table Store_Information
Date
Sales store_name
Los Angeles
San Diego
Los Angeles
Boston
: WHERE
:
SELECT "column_name"
FROM "table_name"
WHERE "condition"
: . :
Table Store_Information
Date
Sales store_name
store_name
Los Angeles
: AND OR
where .
AND OR where .
"SELECT "column_name
"FROM "table_name
"WHERE "simple condition
{[AND|OR] "simple condition"}+
{}+ .
AND OR .
: .
:
Table Store_Information
Date
Sales store_name
store_name
Los Angeles
San Francisco
COUNT .
. .
SELECT COUNT("column_name") FROM table_name
: :
Store_Information Table
store_name
Los Angeles
San Diego
Los Angeles
Boston
Sales
$1500
$250
$300
$700
Date
Jan-05-1999
Jan-07-1999
Jan-08-1999
Jan-08-1999
(count(store_name
COUNT DISTINCT .
:
. SUM
.
.
Date
SUM(Sales) store_name
Los Angeles
$1800
San Diego
$250
Boston
$700
Group By
select . .
.
.
" SELECT "column_name
" FROM "table_name
"WHERE "condition
[ ORDER BY "column_name" [ASC, DESC
][ where where .
order ASC . )(a to z DESC (z to
).a ACS.
.
:
column_name1" [ASC, DESC], "column_name2" [ASC, DESC" ORDER BY
: . .
Table Store_Information
Sales store_name
Date
Sales store_name
Date
where . like
) .
(.
"SELECT "column_name
"FROM "table_name
}WHERE "column_name" LIKE {PATTERN
:
' : 'ABC% ABC .
' : '%XYZ XYZ .
' : '%AN% AN .
: . .
Table Store_Information
Date
Sales store_name
Date
Sales store_name
: BETWEEN
IN
value1 . BETWEEN
. value2
SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2'
January January 6, 1999 . :
. 10, 1999
Table Store_Information
store_name
Sales
Date
Los Angeles
$1500
Jan-05-1999
San Diego
$250
Jan-07-1999
Los Angeles
$300
Jan-08-1999
Boston
$700
Jan-08-1999
store_name
Sales
Date
San Diego
$250
Jan-07-1999
San Francisco
$300
Jan-08-1999
Boston
$700
Jan-08-1999
.
HAVING where .
. query Having .
. group by having
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithematic function condition)
. :
Table Store_Information
Date
Sales store_name
SUM(Sales) store_name
$1800
Los Angeles
SQL . query
query .
:
][SQL Statement 1
MINUS
][SQL Statement 2
).
(
Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
$250 Jan-07-1999
San Diego
Boston
Date
Jan-07-1999 $250
Jan-10-1999 $535
Jan-11-1999 $320
Jan-12-1999 $750
SELECT Date FROM Store_Information
MINUS
SELECT Date FROM Internet_Sales
:
Date
Jan-05-1999
Jan-08-1999
Union query .
union join .
. union
. union
). . ( select Distinct
][SQL Statement 1
UNION
][SQL Statement 2
: .
. .
Table Store_Information
Sales store_name
Date
:
][SQL Statement 1
UNION ALL
][ SQL Statement
: .
. . union .
Table Store_Information
Sales store_name
Date
:
][SQL Statement 1
INTERSECT
][Statement 2 SQL
: .
. . union .
Table Store_Information
Sales store_name
Date
$535 Jan-10-1999
$320 Jan-11-1999
$750 Jan-12-1999
SELECT Date FROM Store_Information
INTERSECT
SELECT Date FROM Internet_Sales
:
Date
Jan-07-1999
.
.
.
.
: From
.
join . Join
alias .
"SELECT "table_alias"."column_name1" "column_alias
"FROM "table_name" "table_alias
. .
: .
Table Store_Information
Sales store_name
Date
$1800
San Diego
$250
Boston
$700
: IN
SQL IN .
where .
.
. .
.
"SELECT "column_name
"FROM "table_name
)WHERE "column_name" IN ('value1', 'value2', ...
: .
.
Table Store_Information
Date
Sales store_name
Date
Sales store_name
join .
.
Table Store_Information
Sales store_name
Date
Boston
East
New York
West
San Diego
.
Geography Store_Information
.
.
store_name .
.
SELECT A1.region_name REGION, SUM(A2.Sales) SALES
FROM Geography A1, Store_Information A2
WHERE A1.store_name = A2.store_name
GROUP BY A1.region_name
:
SALES REGION
East
$700
$2050 West
sql . region_name
Geography REGION . sales
Store_Information sales .
Geography . A1 Store_information . A2
.
Geography.region_name REGION, SUM(Store_Information.Sales) SELECT
SALES
SQL .
.
. where join
. " "store_name Geography
Store_Information .
where . where
join .
. 4 x 4 = 16
.
.
outer join .
.
") "(+ where .
Table Store_Information
Sales store_name
Date
Table Geography
store_name region_name
East
Boston
East
New York
San Diego
Geography
. join
New York .
.
SELECT A1.store_name, SUM(A2.Sales) SALES
FROM Georgraphy A1, Store_Information A2
)WHERE A1.store_name = A2.store_name (+
GROUP BY A1.store_name
oracle .
:
SALES store_name
Boston
$700
New York
$1800 Los Angeles
$250 San Diego
: NULL .
New York Store_Information .
. SQL.
SUM . AVG
: .
Table Store_Information
Sales store_name
Date
Sales : SUM