Interviews World
 .Net (134)
 
  .Net Framework(14)
  .Net Memory Management(2)
  .Net Web Service(6)
  .Net Remoting(30)
  .Net Security(2)
  .Net Threading(8)
  .Net Architecture(2)
  Basic C#(32)
  VB.Net(2)
  .Net Window Service(3)
  .Net Window Forms(14)
  Advanced C#(23)
 
 ASP.Net (26)
 
  ASP.NET General(5)
  ASP.NET Caching(9)
  ASP.NET Ajax(1)
  ASP.NET Session(7)
  ASP.NET Localisation(2)
  ASP.NET 1.1(2)
  ASP.NET 2.0(2)
  ASP.NET 3.5(2)
 
 Database (78)
 
  SQL Server 2000(20)
  SQL Server 2005(17)
  SQL Server 2008(40)
 
 ADO.Net (7)
 
  General ADO.NET(7)
 
 Object Oriented (27)
 
  Basic Object Oriented(19)
  Advanced Object Oriented(8)
 
 XML (1)
 
  Basic XML(1)
 
 MS Dynamics (1)
 
  MS Dynamics GP 9(2)
  MS Dynamics GP 10(1)
  MS Dynamics Soloman(2)
  MS Dynamics CRM 3.0(2)
  MS Dynamics CRM 4.0(2)
 
 Sharepoint (65)
 
  Basic SharePoint(35)
  SharePoint Server 2003(4)
  SharePoint Server 2007(25)
 
 HR (2)
 
  Basic HR(2)
 
 Java (2)
 
  Basic Java(2)
 
 PHP (2)
 
  Basic PHP(2)
 
 Others (2)
 
  Java Script(2)
 
 
  Welcome to Interviews World
 


Question : SQL Server allows you to create indexes with the option IGNORE_DUP_KEY = ON (or just IGNORE_DUP_KEY before SQL Server 2005). Which of the following statements about this option are true?

Answer :

 

  • This option breaks the ACID properties of SQL Server.
  • This option can cause nondeterministic results.
  • This option may only be specified for unique indexes

The IGNORE_DUP_KEY option controls what happens if execution of a multi-row INSERT causes violation of uniqueness in an index. Default behaviour is to give an error message and undo the entire INSERT statement, but with IGNORE_DUP_KEY on, a warning is given and only the offending rows are refused and other rows are still inserted. This breaks atomicity (one of the ACID properties), since a transaction is only atomic if it either completes completely, or fails completely.

If a key value already exists in the destination and that same key value is in the source, then none of the source rows are accepted. This is deterministic. However, if a key value is not in the destination but twice or more in the source, then the first row processed is accepted and the others are not - and which row is processed first is nondeterministic.

The IGNORE_DUP_KEY option makes no sense for a nonunique index, and may not be specified in a CREATE INDEX statement without the UNIQUE keyword; SQL Server will return error 1916 if you attempt to violate this rule. To my surprise, the syntax for CREATE TABLE and ALTER TABLE does allow you to specify the IGNORE_DUP_KEY option for PRIMARY KEY and UNIQUE constraints.

The ANSI standard contains nothing about indexes; they are considered an implementation detail and database vendors have complete freedom in this area. As such, this option is not technically in violation of the ANSI standard (though the possibility of specifying it for a PRIMARY KEY or UNIQUE constraint does constitute a violation of the standard, and the behaviour of this option does go against the ACID properties, one of the basic principles of relational databases).

 
 
  Website Highlights
 



















 
 
 
  Newsleter
 
Enter your Email:
Newsletter