0% found this document useful (0 votes)
7 views10 pages

sql

Uploaded by

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

sql

Uploaded by

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

SQL> create table livres(id_livre number primary key,titre varchar2(20) not

null,auteur varchar2(20) not null,genre varchar2(20),date_publication date);

Table created.

SQL> create table clients (client_id number primary key,nom varchar2(20) not
null,prenom varchar2(20) not null,email varchar2(20) not null unique,adresse
varchar2(20));

Table created.

SQL> create table commandes (commande_id number primary key,date_commande date not
null,montant_total NUMBER(9,2) ,constraint check_montant check(montant_total
>0) ,client_id number ,foreign key(client_id) references clients(client_id));

Table created.

SQL> CREATE TABLE DETAILS (


2 2 DETAILS_id NUMBER PRIMARY KEY,
3 3 quantite NUMBER CONSTRAINT check_quantite CHECK (quantite > 0),
4 4 prix_unitaire NUMBER(5, 2) CONSTRAINT check_prix_unitaire CHECK
(prix_unitaire > 0),
5 5 commande_id NUMBER,
6 6 livre_id NUMBER,
7 7 CONSTRAINT fk_commande FOREIGN KEY (commande_id) REFERENCES commandes
(commande_id),
8 8 CONSTRAINT fk_livre FOREIGN KEY (livre_id) REFERENCES livres
(id_livre)
9 9 );
2 DETAILS_id NUMBER PRIMARY KEY,
*
ERROR at line 2:
ORA-00904: : invalid identifier

SQL> CREATE TABLE DETAILS (


2 DETAILS_id NUMBER PRIMARY KEY,
3 quantite NUMBER CONSTRAINT check_quantite CHECK (quantite > 0),
4 prix_unitaire NUMBER(5, 2) CONSTRAINT check_prix_unitaire CHECK
(prix_unitaire > 0),
5 commande_id NUMBER,
6 livre_id NUMBER,
7 CONSTRAINT fk_commande FOREIGN KEY (commande_id) REFERENCES commandes
(commande_id),
8 CONSTRAINT fk_livre FOREIGN KEY (livre_id) REFERENCES livres
(id_livre)
9 );

Table created.

SQL> create table editeurs(editeur_id number primary key,nom varchar2(20),adresse


varchar2(20));

Table created.

SQL> alter table clients modify (email varchar2(200));

Table altered.
SQL> alter table editeurs add constraint uq_client_email unique;
alter table editeurs add constraint uq_client_email unique
*
ERROR at line 1:
ORA-00906: missing left parenthesis

SQL> alter table editeurs add constraint uq_client_email unique(adresse);

Table altered.

SQL> alter table editeurs rename column adresse to adresse_editeur;

Table altered.

SQL> alter table commandes drop constraint montant_total;


alter table commandes drop constraint montant_total
*
ERROR at line 1:
ORA-02443: Cannot drop constraint - nonexistent constraint

SQL> alter table commandes drop constraint check_montant;

Table altered.

SQL> alter table commandes add constraint check_montant montant_total>0;


alter table commandes add constraint check_montant montant_total>0
*
ERROR at line 1:
ORA-00902: invalid datatype

SQL> alter table commandes add constraint check_montant


montant_total>0(montant_total);
alter table commandes add constraint check_montant montant_total>0(montant_total)
*
ERROR at line 1:
ORA-00902: invalid datatype

SQL> alter table commandes add constraint check_montant check(montant_total=>10);


alter table commandes add constraint check_montant check(montant_total=>10)
*
ERROR at line 1:
ORA-00920: invalid relational operator

SQL> alter table commandes add constraint check_montant check(montant_total>10 or


montant_total =10);

Table altered.

SQL> alter table clients disable constraint uq_client_email;


alter table clients disable constraint uq_client_email
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_CLIENT_EMAIL) - no such constraint
SQL> alter table clients disable constraint uq_client_email;
alter table clients disable constraint uq_client_email
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_CLIENT_EMAIL) - no such constraint

SQL> alter table editeurs drop constraint uq_client_email unique;


alter table editeurs drop constraint uq_client_email unique
*
ERROR at line 1:
ORA-01735: invalid ALTER TABLE option

SQL> alter table editeurs drop constraint uq_client_email;

Table altered.

SQL> alter table clients add constraint uq_client_email unique(email);


alter table clients add constraint uq_client_email unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> alter table clients disable constraint uq_client_email;


alter table clients disable constraint uq_client_email
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_CLIENT_EMAIL) - no such constraint

SQL> SELECT constraint_name, constraint_type


2 FROM user_constraints
3 WHERE table_name = 'Clients';

no rows selected

SQL> SELECT constraint_name, column_name


2 FROM user_cons_columns
3 WHERE table_name = 'Clients';

no rows selected

SQL> ALTER TABLE Clients DISABLE CONSTRAINT UQ_CLIENT_EMAIL;


ALTER TABLE Clients DISABLE CONSTRAINT UQ_CLIENT_EMAIL
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_CLIENT_EMAIL) - no such constraint

SQL> alter table clients add constraint uq_client_email unique(email);


alter table clients add constraint uq_client_email unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table
SQL> alter table clients add constraint uq_client_emailm unique(email);
alter table clients add constraint uq_client_emailm unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> alter table clients add constraint uq_client_email unique(email);


alter table clients add constraint uq_client_email unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> alter table clients add constraint uq_client_email unique(email);


alter table clients add constraint uq_client_email unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> ALTER TABLE Clients DISABLE CONSTRAINT UQ_CLIENT_EMAIL;


ALTER TABLE Clients DISABLE CONSTRAINT UQ_CLIENT_EMAIL
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_CLIENT_EMAIL) - no such constraint

SQL> ALTER TABLE Clients DISABLE CONSTRAINT uq_email_unique;


ALTER TABLE Clients DISABLE CONSTRAINT uq_email_unique
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_EMAIL_UNIQUE) - no such constraint

SQL> ALTER TABLE Clients DISABLE CONSTRAINT uq_client_email;


ALTER TABLE Clients DISABLE CONSTRAINT uq_client_email
*
ERROR at line 1:
ORA-02431: cannot disable constraint (UQ_CLIENT_EMAIL) - no such constraint

SQL> alter table clients add constraint uq_client_email unique(email);


alter table clients add constraint uq_client_email unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> alter table clients add constraint uq_client_email2 unique(email);


alter table clients add constraint uq_client_email2 unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> alter table clients add constraint uq_client_emai unique(email);


alter table clients add constraint uq_client_emai unique(email)
*
ERROR at line 1:
ORA-02261: such unique or primary key already exists in the table

SQL> Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 -
64bit Production
^C
C:\Users\anask.ANAS>connect emsitpg61
'connect' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\anask.ANAS>sqlplus

SQL*Plus: Release 11.2.0.2.0 Production on Sat Oct 26 00:08:38 2024

Copyright (c) 1982, 2014, Oracle. All rights reserved.

Enter user-name: emsitpg61


Enter password:

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

SQL> SELECT constraint_name, constraint_type


2 FROM user_constraints
3 WHERE table_name = 'CLIENTS';

CONSTRAINT_NAME C
------------------------------ -
SYS_C007064 C
SYS_C007065 C
SYS_C007066 C
SYS_C007067 P
SYS_C007068 U

SQL> set linesize 300


SQL> WHERE table_name = 'CLIENTS';
SP2-0734: unknown command beginning "WHERE tabl..." - rest of line ignored.
SQL> SELECT constraint_name, constraint_type
2 FROM user_constraints
3 WHERE table_name = 'CLIENTS';

CONSTRAINT_NAME C
------------------------------ -
SYS_C007064 C
SYS_C007065 C
SYS_C007066 C
SYS_C007067 P
SYS_C007068 U

SQL> SELECT constraint_name, column_name


2 FROM user_cons_columns
3 WHERE table_name = 'CLIENTS';

CONSTRAINT_NAME
------------------------------
COLUMN_NAME
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
SYS_C007064
NOM

SYS_C007065
PRENOM

SYS_C007066
EMAIL

CONSTRAINT_NAME
------------------------------
COLUMN_NAME
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
SYS_C007067
CLIENT_ID

SYS_C007068
EMAIL

SQL> ALTER TABLE Clients DISABLE CONSTRAINT sys_c007068;

Table altered.

SQL> ALTER TABLE Clients drop CONSTRAINT sys_c007068;

Table altered.

SQL> alter table clients add constraint uq_client_email unique(email);

Table altered.

SQL> alter table clients disable constraint uq_client_email ;

Table altered.

SQL> alter table livres add(ISBN varchar2(20));

Table altered.

SQL> alter table clients drop column adresse;

Table altered.

SQL> alter table livres add(editeur_id number);

Table altered.

SQL> alter table livres add constraint fk_editeur foreign key (editeur_id)
references editeurs(editeur_id);

Table altered.
SQL> alter table details modify(10,2);
alter table details modify(10,2)
*
ERROR at line 1:
ORA-00904: : invalid identifier

SQL> alter table details modify prix_unitaire(10,2);


alter table details modify prix_unitaire(10,2)
*
ERROR at line 1:
ORA-00902: invalid datatype

SQL> alter table details modify prix_unitaire number(10,2);

Table altered.

SQL> create table avis(avis_id number primary key,commentaire varchar(50),note


number check(note =>1 and note <=5),client_id number,livre_id number,constrai
nt fk_client foreign key (client_id) references clients(client_id),constraint
fk_livre foreign key (livre_id) references livres (livre_id) );
create table avis(avis_id number primary key,commentaire varchar(50),note number
check(note =>1 and note <=5),client_id number,livre_id number,constraint fk_client
foreign key (client_id) references clients(client_id),constraint fk_livre foreign
key (livre_id) references livres (livre_id) )

*
ERROR at line 1:
ORA-00920: invalid relational operator

SQL> create table avis(avis_id number primary key,commentaire varchar(50),note


number check(note =>1 and note <=5),client_id number,livre_id number,constraint
fk_client foreign key (client_id) references clients(client_id),constraint fk_livre
foreign key (livre_id) references livres(livre_id) );
create table avis(avis_id number primary key,commentaire varchar(50),note number
check(note =>1 and note <=5),client_id number,livre_id number,constraint fk_client
foreign key (client_id) references clients(client_id),constraint fk_livre foreign
key (livre_id) references livres(livre_id) )

*
ERROR at line 1:
ORA-00920: invalid relational operator

SQL> create table avis(avis_id number primary key,commentaire varchar(50),note


number check(note >=1 and note <=5),client_id number,livre_id number,constrai
nt fk_client foreign key (client_id) references clients(client_id),constraint
fk_livre foreign key (livre_id) references livres(livre_id) );
create table avis(avis_id number primary key,commentaire varchar(50),note number
check(note >=1 and note <=5),client_id number,livre_id number,constraint fk_client
foreign key (client_id) references clients(client_id),constraint fk_livre foreign
key (livre_id) references livres(livre_id) )

*
ERROR at line 1:
ORA-00904: "LIVRE_ID": invalid identifier

SQL> create table avis(avis_id number primary key,commentaire varchar(50),note


number check(note >=1 and note <=5),client_id number,livre_id number,constraint
fk_client foreign key (client_id) references clients(client_id),constraint fk_livre
foreign key (livre_id) references livres(id_livre) );
create table avis(avis_id number primary key,commentaire varchar(50),note number
check(note >=1 and note <=5),client_id number,livre_id number,constraint fk_client
foreign key (client_id) references clients(client_id),constraint fk_livre foreign
key (livre_id) references livres(id_livre) )

*
ERROR at line 1:
ORA-02264: name already used by an existing constraint

SQL> create table avis(avis_id number primary key,commentaire varchar(50),note


number check(note >=1 and note <=5),client_id number,livre_id number,constraint
fk_client foreign key (client_id) references clients(client_id),constraint
fk_livre_id foreign key (livre_id) references livres(id_livre) );

Table created.

SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
LIVRES
CLIENTS
COMMANDES
DETAILS
EDITEURS
AVIS

6 rows selected.

SQL> alter table clients modify adresse varchar(500);


alter table clients modify adresse varchar(500)
*
ERROR at line 1:
ORA-00904: "ADRESSE": invalid identifier

SQL> alter table clients modify adresse_editeur varchar(500);


alter table clients modify adresse_editeur varchar(500)
*
ERROR at line 1:
ORA-00904: "ADRESSE_EDITEUR": invalid identifier

SQL> alter table clients modify adresse_editeurs varchar(500);


alter table clients modify adresse_editeurs varchar(500)
*
ERROR at line 1:
ORA-00904: "ADRESSE_EDITEURS": invalid identifier

SQL> alter table clients modify adresse varchar2(500);


alter table clients modify adresse varchar2(500)
*
ERROR at line 1:
ORA-00904: "ADRESSE": invalid identifier

SQL> alter table clients modify adress varchar2(500);


alter table clients modify adress varchar2(500)
*
ERROR at line 1:
ORA-00904: "ADRESS": invalid identifier

SQL> ALTER TABLE clients MODIFY adresse VARCHAR2(500);


ALTER TABLE clients MODIFY adresse VARCHAR2(500)
*
ERROR at line 1:
ORA-00904: "ADRESSE": invalid identifier

SQL> SELECT COLUMN_NAME


2 FROM USER_TAB_COLUMNS
3 WHERE TABLE_NAME = 'CLIENTS';

COLUMN_NAME
------------------------------
CLIENT_ID
NOM
PRENOM
EMAIL

SQL> alter table clients add adresse varchar(20);

Table altered.

SQL> ALTER TABLE clients MODIFY adresse VARCHAR2(500);

Table altered.

SQL> alter table editeurs rename column nom to nom_editeur;

Table altered.

SQL> alter table avis add constraint ck_note_range check(note>=1 and note <=5);

Table altered.

SQL> alter table avis add (date_avis date);

Table altered.

SQL> alter table avis disable ck_note_range ;


alter table avis disable ck_note_range
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> alter table avis disable constraint ck_note_range ;


Table altered.

SQL> alter table livres add (pages number);

Table altered.

SQL> alter table details drop column prix_unitaire;

Table altered.

SQL> alter table livres add (prix number);

Table altered.

SQL> alter table avis modify commentaire varchar(1000);

Table altered.

SQL>

You might also like