Differences between UNIQUE and DISTINCT in select statements

Answer Posted / karthicksharma

As said earlier UNIQUE is a constraint and can be used
during a table creation to prevent duplication of data .

-----------------------------------------------------
CREATING A TABLE USING UNIQUE CONSTRAINT:
=================================================

eg:
SQL> create table empl1 (name varchar2(15),no number(5)
unique);

Table created.

-----------------------------------------------------

So from this it is clearly implied that UNIQUE constraint
is used to prevent INSERTION AS WELL AS RETRIVAL of non-
duplicate data.

whereas DISTINCT clause can only be used for RETRIVAL of
non-duplicate data.

Whereas DISTINCT is a clause and cannot be used during a
table creation to limit the duplication of data.

-----------------------------------------------------
CREATING A TABLE USING DISTINCT CLAUSE:
===========================================
eg:
create table empl2(name varchar2(15),no number(5) distinct)
*
ERROR at line 1:
ORA-00907: missing right parenthesis

-----------------------------------------------------

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how tsql statements can be written and submitted to the database engine? : Transact sql

722


what is not null constraint? : Sql dba

740


What are the two parts of design view?

782


Can we perform dml in function?

810


What are the main features of cursor?

839


What is the current version of postgresql?

749


How to connect a sql*plus session to an oracle server?

838


What is difference between table and view?

719


Is pl sql better than sql?

727


What are pl/sql cursors?

738


What is error ora-01000: maximum open cursors exceeded

796


What are the usages of sql?

756


How can we connect an Android App to an Oracle database and use the PL/SQL procedural code?

813


Why do we use subquery?

721


Can dml statements be used in pl/sql?

785