Tuesday, April 8, 2014

Question of the Week -08/04/2014


Suppose we need to find out the name of all the months in a given year (Year will be given as an input parameter) where first day of the month falls on weekend (Saturday or Sunday). 

So what should be the query/stored procedure to get the above result?

DMCA.com

Answer - Objective Question (How many Null values in an unique constraint can be inserted in SQL Server)

Question:- How many NULL value allowed in a column in which Unique constraint is defined in SQL Server?

Options:-

a) 1

b) 2

c) More than 1

Answer :- Option a) 1

In SQL Server, we can Insert only one null value in a column where we have defined the Unique Constraint.

For Example , suppose we made a table test_unique, whose script is given below:-

create table test_unique (id int unique)

Now we insert the following values in it.

insert into test_unique(id) values (1)

insert into test_unique(id) values (2)

insert into test_unique(id) values (NULL)

insert into test_unique(id) values (3)

Here we inserted one null value before inserting 3.

If we see the records in the table , it shows the following data.


Let try to insert another NULL value and see what error it gives.

insert into test_unique(id) values (NULL)

Then it will gives the following error


So, In SQL server we can insert only one NULL value in a column where Unique constraint is defined.


DMCA.com

Sunday, March 16, 2014

Happy Holi



Holi is the time to unwind de-stress and bond with sweets,Thandai and colours.Come let’s rejuvenate by immersing ourselves in the colour of joy,happiness and laughter!Happy Holi!

Saturday, January 11, 2014

Question of the Week - 11/1/2014

Question:- Suppose there are two tables A and B and we need to write 3 SQL queries which returns the record set as shown in the below figure.


First Query:-

In this case, you have to write a SQL Query using SQL JOIN which return the data which is not common to these two tables A& B as shown in the shaded part in 1st figure.


Second Query:-

 In this case, you have to write a SQL Query using SQL JOIN which will return the data from table A which is not in the table B as shown as shaded part in 2nd figure.



Third Query:-

 In this case, you have to write a SQL Query using SQL JOIN which will return the data from table B which is not in the table A as shown as shaded part in 3rd figure.








Previous Questions and their Answers


 Question of the Week - 2/1/2014 - Question 1
  
 Answer

 Question of the Week - 28/12/2013 - Question 2

 Answer

 Question of the Week -25/12/2013- Question1


 Answer

DMCA.com