Как составлять SQL-запросы - подробные примеры

. , . , ..

, , « » - . SQL. .

. (). - .

, , , . . .

, . .

– , . . .

– . , .





SQL?

SQL (. Structured Query Language - ) . . , , sql .

sql




1992 . , ANSI SQL. , ORACLE Microsoft SQL Server. , SQL . :

  • ;
  • ;
  • ;
  • .

SQL

. SQL , .

INT
REAL
TEXT
DATEsql ""
TIME
CHAR

sql





, SQL :

  • SQL
  • , .

CREATE DATABASE < >;. , .

CREATE TABLE :

Commodity :

commodity_idID
vendor_idID ( Vendors)
commodity_name
commodity_price
commodity_desc

:

CREATE TABLE Commodity

(commodity_id CHAR(15) NOT NULL,

vendor_id CHAR(15) NOT NULL,

commodity_name CHAR(254) NULL,

commodity_price DECIMAL(8,2) NULL,

commodity_desc VARCHAR(1000) NULL );

. , . (NULL) (NOT NULL), .

sql




- SQL . , . :

SELECT commodity_name FROM Commodity

SELECT , FROM .

Commodity_name , .. . ORDER BY.

, :

SELECT commodity_id, commodity_name, commodity_price FROM Commodity

. «*»:

SELECT * FROM Commodity

  • SELECT :
  • ( ORDER BY)
  • (WHERE)
  • (GROUP BY)

sql

SQL INSERT. :

  • ;
  • ;
  • .

() . :

INSERT INTO Commodity VALUES('106 ', '50', 'Coca-Cola', '1.68', 'No Alcogol , )

. VALUES . , NULL. , .

, :

INSERT INTO Commodity (commodity_id, vendor_id, commodity_name)

VALUES('106 ', ‘50', 'Coca-Cola',)

, , .

INSERT , SELECT.

sql




UPDATE. :

  • .
  • .

UPDATE :

  • , ;
  • ;
  • .

. , ID=106 , . :

UPDATE Commodity SET commodity_price = '3.2' WHERE commodity_id = '106'

, Commodity, , SET - , WHERE ID.

SET -, . , :

UPDATE Commodity SET commodity_name=’Fanta’, commodity_price = '3.2' WHERE commodity_id = '106'

NULL, . , NULL - «» , . :

UPDATE Commodity SET commodity_desc = NULL WHERE commodity_id = '106'

sql




SQL DELETE. :

  • ;
  • .

:

DELETE FROM Commodity WHERE commodity_id = '106'

DELETE FROM , . WHERE , . ID=106. WHERE .. . .

DELETE . , .

SQL Microsoft Access

sql access




Microsoft Access , , , , SQL Access (Query Designer), SQL .

, Access SQL- ODBC . Access .

SQL

SQL , , .., SQL . .

:

  • Oracle Database - PL/SQL
  • Interbase, Firebird – PSQL
  • Microsoft SQL Server - Transact-SQL
  • PostgreSQL - PL/pgSQL.

SQL

MySQL GNU General Public License. . -, XAMPP, WAMP LAMP, .

Sun Microsystems Oracle. 64 , SQL:2003, .




All Articles