Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 many scalar data types are supported in pl/sql?

982


How to avoid using cursors? What to use instead of cursor and in what cases to do so?

1134


Why primary key is required?

943


what happens when the column is set to auto increment and you reach the maximum value for that table? : Sql dba

979


What is %rowtype in pl sql?

933


Is pl sql a scripting language?

977


How do I enable sql encryption?

975


How can we avoid duplicating records in a query?

933


how to use regular expression in pattern match conditions? : Sql dba

975


Do stored procedures prevent sql injection?

925


What is the most important ddl statements in sql are?

952


How can we store rows in PL/SQL using array?

1167


Is it possible for a table to have more than one foreign key?

989


Can we have two clustered index on a table?

976


Can we join same table in sql?

966