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
How many scalar data types are supported in pl/sql?
How to avoid using cursors? What to use instead of cursor and in what cases to do so?
Why primary key is required?
what happens when the column is set to auto increment and you reach the maximum value for that table? : Sql dba
What is %rowtype in pl sql?
Is pl sql a scripting language?
How do I enable sql encryption?
How can we avoid duplicating records in a query?
how to use regular expression in pattern match conditions? : Sql dba
Do stored procedures prevent sql injection?
What is the most important ddl statements in sql are?
How can we store rows in PL/SQL using array?
Is it possible for a table to have more than one foreign key?
Can we have two clustered index on a table?
Can we join same table in sql?