Can we use more than one null value for unique key?

Answers were Sorted based on User's Feedback



Can we use more than one null value for unique key?..

Answer / ashwin

you can insert as many values as u want, in uniquelly
declared column

some people r saying that if u insert more than one null
value in unique column of relation then null is duplicated
which violets unique key property..........well this saying
is totally rubbish......are pehle insert karke dekho phir
bolo as simple as that...

Is This Answer Correct ?    4 Yes 0 No

Can we use more than one null value for unique key?..

Answer / shailendra chauhan

Yes, We can insert more the one NULL with unique key.
cos, Neither null is equal to null Nor null is not equal to
null.

Is This Answer Correct ?    8 Yes 5 No

Can we use more than one null value for unique key?..

Answer / christina

Yes, We can use more then one null value in unique key ,
because "null" means undefined or unknown so we can add any
number of null values in unique key...
This is the major difference between primary nd unique key,
Primary key doesn't allow null values to be entered into
the columns marked as priamry key and Unique allow us to
enter null values...............

Is This Answer Correct ?    5 Yes 2 No

Can we use more than one null value for unique key?..

Answer / sam

Yes ,we can insert more null value in a table having unique
key,Bcoz one null vale is different frm another null value.

Is This Answer Correct ?    6 Yes 4 No

Can we use more than one null value for unique key?..

Answer / arika

We can insert duplicate nul values in palce of using unique
key constrint.Because all nulls are not equal.


ex:-
select * from emp where comm=null;
explenation;
here equal operator not support null value because
all nulls are not equal
ex:-
select * from emp where comm is null;
explenation:
'is' operator suport null

Is This Answer Correct ?    2 Yes 0 No

Can we use more than one null value for unique key?..

Answer / praveen hr

UNIQUE Constraints

You can use UNIQUE constraints to make sure that no
duplicate values are entered in specific columns that do
not participate in a primary key. Although both a UNIQUE
constraint and a PRIMARY KEY constraint enforce uniqueness,
use a UNIQUE constraint instead of a PRIMARY KEY constraint
when you want to enforce the uniqueness of a column, or
combination of columns, that is not the primary key.

Multiple UNIQUE constraints can be defined on a table,
whereas only one PRIMARY KEY constraint can be defined on a
table.

Also, unlike PRIMARY KEY constraints, UNIQUE constraints
allow for the value NULL. However, as with any value
participating in a UNIQUE constraint, only one null value
is allowed per column.

A UNIQUE constraint can be referenced by a FOREIGN KEY
constraint.

Link from MSDN http://msdn.microsoft.com/en-
us/library/ms191166.aspx

Is This Answer Correct ?    2 Yes 1 No

Can we use more than one null value for unique key?..

Answer / a

we have to use computed column to insert multiple null values.

Is This Answer Correct ?    1 Yes 0 No

Can we use more than one null value for unique key?..

Answer / raman

Primary Key is a combination of Unique and NOT NULL
Constraints so it can’t have duplicate values or any NUll

Whereas for Oracle UNIQUE Key can have any number of NULL
but for SQL Server It can have only one NULL

Is This Answer Correct ?    1 Yes 0 No

Can we use more than one null value for unique key?..

Answer / hassan khan

A unique key constraint does not imply the NOT NULL
constraint in practice. Because NULL is not an actual value
(it represents the lack of a value), when two rows are
compared, and both rows have NULL in a column, the column
values are not considered to be equal. Thus, in order for a
unique key to uniquely identify each row in a table, NULL
values must not be used. According to the SQL standard and
Relational Model theory, a unique key (unique constraint)
should accept NULL in several rows/tuples — however not all
RDBMS implement this feature correctly.

Is This Answer Correct ?    1 Yes 0 No

Can we use more than one null value for unique key?..

Answer / sabariesh thavamani

i worked out the coding in the above using oracle 9 i, but
i could not get the correct answer what he told.. try it

SQL> create table sab(name varchar2(10) unique);

Table created.

SQL> insert into sab values('&sab');
Enter value for sab: null
old 1: insert into sab values('&sab')
new 1: insert into sab values('null')

1 row created.

SQL> /
Enter value for sab: null
old 1: insert into sab values('&sab')
new 1: insert into sab values('null')
insert into sab values('null')
*
ERROR at line 1:
ORA-00001: unique constraint (LPUSER18.SYS_C0038068)
violated


SQL> /
Enter value for sab: sabari
old 1: insert into sab values('&sab')
new 1: insert into sab values('sabari')

1 row created.

SQL> /
Enter value for sab: null
old 1: insert into sab values('&sab')
new 1: insert into sab values('null')
insert into sab values('null')
*
ERROR at line 1:
ORA-00001: unique constraint (LPUSER18.SYS_C0038068)
violated


SQL> select * from sab
2 ;

NAME
----------
null
sabari
try it....

Is This Answer Correct ?    5 Yes 5 No

Post New Answer

More SQL PLSQL Interview Questions

What's the difference between inner join and left join?

0 Answers  


Is left join faster than inner join?

0 Answers  


create SQL (both DML/DDL) statements appropriate for the creation of relational structures & constraints and other objects for a given case study, the population of these tables and the manipulation (querying/updating) of the stored data. 2. Create, develop and use the PL / SQL Program Units Procedures, Functions as a progression towards Object Oriented Relational Database Programming. 3. Package a collection of logically related Procedures and Functions together to further move towards development of Objects which reflect the principle of Data Abstraction whereby only an Object specified in the Interface is accessible to the end user. 4. Select, create, and use appropriate Database Triggers to impose agreed specific constraints on a Database Table. 5. Provide a full and detailed evaluation which includes a comprehensive test execution plan and its implementation for each of the above. Consider the following case study: Perilous Printing is a medium size printing company that does work for book publishers throughout UK. The company currently has 10 offices, most of which operate autonomously, apart from salaries, which are paid by the head office. Currently the sharing and communication of data, is carried out using multi- user networked access to a centralised RDBMS. Perilous Printing jobs consist of printing books or part of books. A printing job requires the use of materials, such as paper and ink, which are assigned to a job via purchase orders. Each printing job may have several purchase orders assigned to it. Likewise, each purchase order may contain several purchase order items. The following tables form part of the transactional RDB that the company uses: office (office_no, o_addr, o_telno, o_faxno, mgr_nin) staff (staff_no, nin, fname, lname, s_addr, s_telno, gender, dob, position, taxcode, salary, office_no) publisher (pub_no, p_name, p_city, p_telno, p_faxno, credit_code, office_no) book_job (job_no, pub_no, job_date, job_desc, job_type, job_status, supervisor_nin) purchase_order (job_no, po_no, po_date) po_item (job_no, po_no, it_no, qty) item (it_no, it_desc, amt_in_stock, price) office contains details of each office and the office number (office_no) is the key. Each office has a Manager represented by the manager’s national insurance number (mgr_nin). staff contains details of staff; the staff_no is the key. The office that the member of staff works from is given by office_no. publisher contains details of publisher and the publisher number (pub_no) is the key. Publishers are registered with the nearest office in their country, given by office_no, and they are given a credit code that can have the values “AA”, “AB”, “BB”, “BC”, “CC”, “CD” and “DD”. If a publisher is to be deleted then not only the publisher’s entry from the publisher table will have to be removed but all the data associated with the particular supplier has to be deleted too book_job contains details of publishing jobs and the job number (job_no) is the key. The publisher is given by the publisher number (pub_no) and the supervisor for the job by supervisor_nin. The job type can be either null or urgent; whereas the job_status can be “ongoing” or “completed” purchase_order contains details of the purchase orders for each job and the combination of job number and a purchase order number (job_no, po_no) form the key. Each printing job may have several purchase orders assigned to it. item contains details of all materials that can be used in printing jobs and the item number (it_no) is the key. po_item contains details of the items on the purchase order and (job_no, po_no, it_no) forms the key. In the above given database schema, descriptions are strings of characters (at most 30 characters long), any dates (except the job_ date) stored cannot be after the current system date, and quantities and prices are assumed to be non-negative numbers.

0 Answers  


What is embedded sql what are its advantages?

0 Answers  


one of the column in my table contains the data like SAL ---- 1000 1000 2000 3000 3000 So my requirement is i want output like SAL --- 1000 2000 3000 it mean i want to delete duplicate rows in the table permanently and i want output in the above formatow should u write query?

13 Answers   Cap Gemini, TCS,






suppose I have two table one Emp and other is dpt. Emp table has a field ,dept id,name ,sal and dpt table has a field dept id,dept name. Now I want to find out the emplyee list whose sal is between 2000-3000 from dept x.

7 Answers   Geometric Software, IBM,


Are stored procedures faster than queries?

0 Answers  


what are myisam tables? : Sql dba

0 Answers  


What is a mutating table

5 Answers   TCS, Tech Mahindra,


write a query to display diference between two dates in sql server

2 Answers  


How do I view stored procedures?

0 Answers  


What is mutating sql table?

0 Answers  


Categories