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
Is sql microsoft?
What is the difference between function and procedure in pl/sql?
how to add a new column to an existing table in mysql? : Sql dba
How run sql*plus commands that are stored in a local file?
How do temporal tables work?
what is the difference between a having clause and a where clause? : Sql dba
What is difference between stored procedure and trigger?
What is primary key and unique key?
How many primary keys can a table have?
Mention what does the hierarchical profiler does?
How do I partition in sql?
What is the difference between functions, procedures, and packages in pl/sql?
What are sql data types?
Why do we need unique key in a table?
Can a composite key be null?