|
SQL quick reference
|
|
|
|
|
|
Syntax notation in this guide
- [] - optional construction
- {} - repeatable construction
- INSERT - keywords
|
|
Syntax
definition
|
Example
|
|
SELECT [predicate]
{ *
|table.* | [table.]field_1 [AS
alias_2] [, [table.]field_2 [AS
alias_2] [, ...]]}
FROM statement [, ...]
[WHERE... ]
[GROUP BY... ]
[HAVING... ]
[ORDER BY... ]
|
select A as "Value", B as "Sum"
from MyTable
where A>B and A>0
order by B
|
|
INSERT
syntax for add one record:
INSERT INTO table [(field_1[,
field_2[, ...]])]
VALUES (value_1[, value_2[, ...])
Syntax
for subquery based INSERT:
INSERT INTO table [(field_1[,
field_2[, ...]])]
SELECT [source.]field_1[, field_2[,
...] FROM-expression
|
insert into MyTable (A,B)
values (5,80)
|
|
DELETE [table.*]
FROM table
WHERE selection_condition
|
delete
from MyTable
where A>470
|
|
UPDATE table
SET { field = expression_for_new_value
}
[WHERE selection_condition]
|
update
MyTable
set A=40
where A<25
|
|
DROP <object type>
<object name>
Object
types: table, view, index, etc.
|
drop table MyTable
|
|
CREATE TABLE
<table name>
(
field_description,... [CONSTRAINT
<constraint>])
<field description> ::= <field name> <field
type>
<constraint> ::= <constraint_name> PRIMARY KEY (<fields name list>)
|
create
table MyTable
( A integer,
B decimal
)
|
|
GRANT statement[,...]
TO account[,...]
or
GRANT permission[,...]
ON object[,...]
TO
account[,...]
|
GRANT DROP DATABASE, CREATE
TABLE
TO Mary, Peter
GRANT INSERT, UPDATE, DELETE
ON Rating
TO Tom
|
|
REVOKE
statement[,...]
FROM account[,...]
or
REVOKE permission[,...]
ON object[,...]
FROM account[,...]
|
REVOKE CREATE TABLE
FROM Mary
REVOKE INSERT
ON Rating
FROM Tom
|
|
|
|
© Copyright 1998-2011 DTM soft.
|