0% found this document useful (0 votes)
9 views3 pages

Lab 01

The document discusses three variations for creating tables in Oracle with constraints: 1) Without naming constraints, where Oracle assigns names 2) With personalized constraint names 3) Examples of initial data inserts to demonstrate constraint violations referred to by name

Uploaded by

Supremusx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Lab 01

The document discusses three variations for creating tables in Oracle with constraints: 1) Without naming constraints, where Oracle assigns names 2) With personalized constraint names 3) Examples of initial data inserts to demonstrate constraint violations referred to by name

Uploaded by

Supremusx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Laborator 1

Variante de creare ale unui tabel.

1. VARIANTA FARA DENUMIRI ALE CONSTRANGERILOR

Constrangerile pot fi mentionate atat la nivelul fiecarui camp cat si la sfarsit, dupa precizarea campurilor si a
tipurilor lor de date.
Se observa ca in aceasta situatie denumirile constrangerilor sunt alocate de catre Oracle.

CREATE TABLE clienti_ABC (


CODCL NUMBER (4) PRIMARY KEY CHECK (CODCL>1000),
DENCL VARCHAR2 (20),
LOCALIT VARCHAR2(30) NOT NULL
);

CREATE TABLE clienti_ABC1 (


CODCL NUMBER (4) PRIMARY KEY,
DENCL VARCHAR2 (20),
LOCALIT VARCHAR2(30) NOT NULL,
CHECK (CODCL>1000)
);

CREATE TABLE clienti_ABC2 (


CODCL NUMBER (4),
DENCL VARCHAR2 (20),
LOCALIT VARCHAR2(30) NOT NULL,
PRIMARY KEY (CODCL),
CHECK (CODCL>1000)
);

Varianta de mai sus prin care se precizeaza cheia primara la sfarsit, poate fi utilizata si la crearea unei chei primare
duble.

CREATE TABLE clienti_ABC3 (


CODCL NUMBER (4),
DENCL VARCHAR2 (20),
LOCALIT VARCHAR2(30) NOT NULL,
PRIMARY KEY (CODCL, DENCL),
CHECK (CODCL>1000)
);
2. VARIANTA CU DENUMIRI PERSONALIZATE ALE CONSTRANGERILOR

CREATE TABLE clienti_ABC4 (


CODCL NUMBER (4)
CONSTRAINT pk_codcl_abc4 PRIMARY KEY
CONSTRAINT ck_codcl_abc4 CHECK (CODCL>1000),
DENCL VARCHAR2 (20),
LOCALIT VARCHAR2(30)
CONSTRAINT nn_localit_abc4 NOT NULL
);

De asemenea aceste constrangeri pot fi mentionate si la sfarsit.

CREATE TABLE clienti_ABC5 (


CODCL NUMBER (4),
DENCL VARCHAR2 (20),
LOCALIT VARCHAR2(30) CONSTRAINT nn_localit_abc5 NOT NULL,
CONSTRAINT pk_codcl_abc5 PRIMARY KEY (CODCL),
CONSTRAINT ck_codcl_abc5 CHECK (CODCL>1000)
);

3. PRIMELE INSERARI DE DATE

INSERT INTO clienti_ABC VALUES (1200,'Popescu','Arad');

La al doilea rand de date, in mod intentionat, incalcam unicitatea cheii primare

INSERT INTO clienti_ABC VALUES (1200,'Georgescu','Timisoara');

INSERT INTO clienti_ABC VALUES (800,'Georgescu','Timisoara');

Aici este incalcata regula CHECK

Adaugand date asemanatoare in tabela clienti_ABC4, vom observa ca semnalarea erorilor se face prin denumirile
personalizate.
INSERT INTO clienti_ABC4 VALUES (1200,'Popescu','Arad');

INSERT INTO clienti_ABC4 VALUES (1200,'Georgescu','Timisoara');

INSERT INTO clienti_ABC4 VALUES (800,'Georgescu','Timisoara');

You might also like