The SQL language standard was adopted in 1992 and is still in use. It was he who became the standard for many database management systems. Of course, some manufacturers use their own interpretations of the standard. But in any system there are still the main components - SQL statements.
Introduction
Using SQL statements in databases , values, tables are managed and retrieved for further analysis and display. They are a set of keywords by which the system understands what to do with the data.
Several categories of SQL statements are defined:
- definition of database objects;
- value manipulation;
- protection and management;
- Session parameters
- database information;
- static SQL
- dynamic SQL.
SQL statements for data manipulation
, .
INSERT. . , , . :
INSERT INTO
( 1, 2)
VALUES ( 1, 2).
SQL INSERT , :
INSERT INTO
1 ( 1, 2)
SELECT 1, 2
FROM 2
WHERE 2. 1>2
2, 2 1 .
UPDATE. , SQL .
:
UPDATE 1
SET 2 = «»
WHERE 1. 1 = 1
, 1 .
DELETE. . - .
DELETE FROM
WHERE . 1 = 1
. :
DELETE FROM .
SELECT. , .
SELECT
SELECT — . . MS SQL SELECT . .
«*».
SELECT *
FROM 1
1.
WHERE, 1 , 2 1.
SELECT *
FROM 1
WHERE 1. 1 > 2
, .
SELECT 1. 1
FROM 1
, 1. MS SQL , , .
SELECT
1. 1
1. 2
1. 3
«=» AS EQ
1. 2 * 1. 3 AS SUMMA
FROM 1
, 1, EQ SUMMA. «+», 2 3. , :
1 | 2 | 3 | EQ | SUMMA |
1 | 10 | 50 | + | 500 |
2 | 15 | 100 | + | 1500 |
SELECT, - . ORDER BY.
SELECT
1. 1
1. 2
1. 3
FROM 1
ORDER BY 2
:
, 2 .
. , , :
«»
«»
, - . SQL :
SELECT
.
.
.
.
FROM ,
WHERE . = .
, . :
SELECT.
SQL SELECT . .
, «», :
SELECT COUNT (*) AS N
FROM
.
, , , . SUM, MAX, MIN, AVG.
, «»:
:
SELECT
SUM(.) AS SUMMA
MAX(.) AS MAX
MIN(.) AS MIN
AVG(.) AS SRED
FROM
:
SUMMA | MAX | MIN | SRED |
13500 | 10000 | 3500 | 6750 |
, , .
,
SQL
SELECT .
FROM
WHERE . = 1
UNION
SELECT .
FROM ,
WHERE . = 1
, . .
SELECT
SELECT , . FROM. , .
SQL WHERE. SELECT .
GROUP BY, .
. SQL .
LIKE
«». LIKE SQL — . .
, : «» , «». :
SELECT *
FROM
WHERE LIKE `%`
, . «» SQL .
CASE
SQL Server . switch . CASE SQL .
, «» .
:
SELECT *
FROM
WHERE CASE WHEN SELECT MAX() THEN
WHEN SELECT MIN() THEN
END
«». END «», «» «» .
, SQL CASE — COALESCE.
— , , .
, — CREATE TABLE. , . CREATE TABLE, , .
, «» :
CREATE TABLE
( number(10) NOT NULL
varchar(50) NOT NULL
varchar(50) NOT NULL)
, , NULL.
DROP TABLE
— . IF EXISTS. , . :
DROP TABLE IF EXISTS.
CREATE INDEX
SQL , . , , . :
CREATE INDEX _
ON _(_)
T-SQL, Oracle, PL SQL .
ALTER TABLE
, . , . Oracle SQL, Postgres .
ALTER TABLE.
ADD. . : ALTER TABLE _ ADD _ __. IF NOT EXISTS, , ;
DROP. . IF EXISTS, , , ;
CHANGE. . : ALTER TABLE _ CHANGE _ _;
MODIFY. . : ALTER TABLE _ MODIFY _ _ ;
CREATE VIEW
SQL , . , . SQL SELECT. , , .
:
CREATE VIEW AS SELECT FROM *
, .
SQL , . , .
SQL , , .
AS. , , .
BETWEEN. . , . ;.
NOT. .
TRUNCATE. . , . , SQL . TRUNCATE, .
LIMIT. . , . . , . , .
UNION. . . , UNION . : SELECT _ FROM _ UNION SELECT __ FROM _ . .
PRIMARY KEY. « ». , . . , , , .
DEFAULT. , , . , .
SQL
NULL. NULL. , . , , NULL .
. , . , «» . .
. , LIMIT TOP. .
. . ? . .
. , , . .
. , . .
. , . . , .
. . «» , . , , 255, 4- INT, TINYINT 1 .
, SQL — , -, , . SQL .
. , PL SQL , SQL Server. , .
In the future, analogues that could surpass SQL in functionality and performance are unlikely to appear, so this area is a fairly promising niche for any programmer.