, RDMS, , . SQL RDMS.
SQL . , , PHP, , phpMyAdmin, XAMPP, . .
SQL
SQL " ", . IBM SEQUEL, . SQL ISO. :
- ANSI 1986 ;
- ISO (SQL1) 1987 , 1989 ;
- ISO (SQL2) 1992 ;
- SQL3, 1999 ANSI ISO.
ISO SQL 2006 XML-, XML- XML constraint SQL.
ISO, SQL :
MySQL ( MariaDB), PostgreSQL, Oracle, NoSQL, Cassandra — . , SQL, . «», , ODBC (Open Data Base Connectivity). Microsoft 1993 constraint SQL.
SQL - , . . , 1986 .
, . , . Ms SQL constraint :
, , , , . :
- Constraint SQL.
- DEFAULT.
- NOT NULL.
- SINGLE.
- CHECK.
SQL , DEFAULT. , . DEFAULT, .
:
- ;
- - ();
- USER ( );
- NULL;
- CURRENT_DATE ( );
- CURRENT_TIME ( );
- CURRENT_TIMESTAMP ( ).
, , type_field1, field_type2 . . , . , , . , . phpMyAdmin .
|
| |
NUMBER(n,[d]) | n [ d ( ) ] |
SMALLINT | 16- |
INTEGER | 32- |
FLOAT | |
DATE | dd / mm / yy |
TIME | |
TIMESTAMP | |
CHAR(l) | l (l <16383) |
VARCHAR(n) | n (n <16383) |
: CREATE TABLE table_name ( column1 Type_champ1 , column2 Type_champ2 , colonne3 Type_champ3 ... ).
constraint SQL
, . :
- default val— val ;
- not null — () ;
- null — () ( );
- unique — ;
- check (te)— te ;
- pimary key — ( SQL unique constraint ) not null unique;
- references ta [(at)] — at, unique, ta, at , , ta;
- references ta [(at)] on delete cascade — , , ta , , , .
add constraint SQL :
- unique (at1, ..., atN) — ;
- check (te) — te .
SQL . SQL create table.
: (), , (). .
, . , .
NOT NULL , , , , NOT NULL. CHECK () , . NULL, SELECT.
UNIQUE , . CONSTRAINT , , , . CONSTRAINT , . , , , .
SQL alter table constraint
, «»:
id () | nom () | categorie () | stock () | prix () |
1 | | | 5 | 950 |
2 | | | 32 | 35 |
3 | | | 16 | 30 |
4 | | | 147 | 2 |
add constraint SQL . , , , ( 20 ), :
SELECT * FROM produitWHERE categorie = 'informatique' AND stock < 20
:
id () | nom | categorie () | stock () | prix () |
1 | | | 5 | 950 |
3 | | | 16 | 30 |
«» «», :
SELECT * FROM produitWHERE nom = 'ordinateur' OR nom = 'clavier'
:
id () | nom () | categorie () | stock () | prix () |
1 | | | 5 | 950 |
2 | | | 32 | 35 |
, . «» 20, «» 200 SQL alter table add constraint:
SELECT * FROM produitWHERE ( categorie = 'informatique' AND stock < 20 )OR ( categorie = 'fourniture' AND stock < 200 )
3 :
id () | nom () | categorie () | stock () | prix () |
1 | | | 5 | 950 |
2 | | | 16 | 30 |
4 | | | 147 | 2 |
SQL constraint foreign key, , , , . , , PRIMARY KEY, , , .
NULL , . PRIMARY KEY (colonne1, colonne2, ...).
, SQL add constraint foreign key, , , . REFERENCES, , .
FOREIGN KEY (colonne1, colonne2, ...) REFERENCES Nom_de_la_table_etrangere(colonne1,colonne2,...)
— . , . . . :
, . alter . . rowid, , . , , .
, - . , .
(FK) , , FK, . :
, , , . :
create unique index num_sécu on personne.
- , . - ( ENUM ) :
, , , , /. (, , ...). , , , SQL alter constraint. .
:
ALTER TABLE ma_table DISABLE CONSTRAINT ma_constraint;
:
ALTER TABLE ma_table ENABLE CONSTRAINT ma_constraint;
, , () , , , . , , , .
ALTER TBLE . , ALTER .
: . INSERT, .
, .
. .
varchar. , . ALTER TABLE, .
:
, . , , , , (s) , , , .
«» «»:
- ON DELETE - , , .
- CASCADE - , .
- RESTRICT - , .
- SET NULL - NULL , .
- SET DEFAULT - ( ) , , .
«» , , , :
- CASCADE - , .
- RESTRICT - .
- SET NULL - NULL , .
- SET DEFAULT - , , , .
- - , , . , .
: CREATE ASSERTION Nom_de_la_contrainte CHECK (expression_conditionnelle) , , ( ) SELECT.