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

What are expressions?

563


what is the difference between blob and text? : Sql dba

527


Is sql a dbms?

530


Why is sql*loader direct path so fast?

595


Why is normalization important?

536






Can we use delete in merge statement?

512


How many sql commands are there?

673


What are different categories of sql commands?

632


Which is faster view or stored procedure?

502


What is the current version of sql?

538


what is a table called, if it has neither cluster nor non-cluster index? What is it used for? : Sql dba

522


what are date and time intervals? : Sql dba

564


what is 'trigger' in sql? : Sql dba

557


Is it mandatory for the primary key to be given a value when a new record is inserted?

708


How do I edit a stored procedure?

554