Removing a constraint from a table

Here i have given the syntax and query for removing a constraint from a table...

syntax:
------
ALTER TABLE (tbl name) DROP CONSTRAINT (CONSTRAINT name)


Eg:
--
ALTER TABLE Proddet_Details DROP CONSTRAINT  FK_PCIT_Details

How to find 5th maximum number through a query in sql

"How do I find Nth maximum value?" is one of the most asked questions in many
  
  interviews....  Here are some methods.. to solve this..

Use Inner Join
------------------
  select t1.num from number t1 inner join number t2 on t1.num<=t2.num  group by    t1.num having count(t1.num)=5

Use Top Operator

---------------------
Eg1:
Select top 1 num from(Select top 5 num from number order by num desc) T
order by num asc

Eg2:
Select TOP 1 quantity from findmax where quantity NOT IN (Select TOP 4 quantity FROM findmax order by quantity ASC)
order by quantity ASC

How to copy structure of table

syntax:
---------
Select * Into (DestinationTableName) From (SourceTableName) Where 1 = 2

Example:
-----------
Select * Into my_new_table From emp Where 1=2
 

Friends ....this will just create the table structure as the source table

Wont create any constraint or triggers on the table..

and if you also want to copy the data then remove the where clause..  

Friends post  your comments or questions  on my blog to improve my posts .... 

Javascript : Disable Right Click

You can disable right click on ur webpages to prevent others stealing ur images and other things...  place  this code above head tag..

//script language="JavaScript"

var message="Sorry, that function is disabled.";

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
 
// /script>

How to use IN operator ?

Sometimes you want to test a given value against a list of values. Here you can use the special comparison operator IN to get it done. Below i have given two examples using IN operator..

Example 1:

DECLARE @my_id INT;
SET @my_id = 767;
SELECT CASE WHEN
@my_id IN (525, 272, 532, 767, 150, 637)
THEN 'I m Kavya.'
ELSE 'I m not Kavya.'
END;
GO

o/p: I m Kavya


Example 2:

DECLARE @my_id INT;
SET @my_id = 676;
SELECT CASE WHEN
@my_id NOT IN (525, 272, 532, 767, 150, 637)
THEN 'I m not Kavya.'
ELSE 'I m Kavya.'
END;
GO

o/p: I m not Kavya