Thursday 27 September 2012

Silly mistake by me in SQL SERVER

Today I had tried to solved this bug . I have to confess that this take some extra  time by me .

The problem is i create a table name color and insert the field into them and execute this query

select * from color
Black
Blue
Green
Red

After inserting some data i run this query for checking any value is available in it or not

SELECT COUNT(1) color

It seems good becuase i write this query very rapidally and do  not think about this create  a bug?

when i run this it always return 1 . i  am afraid WTF in this .
i spend some time on this but not able to get the error. really i think that is SQL Server corrupted or anything else .
after frustrating i go to took a cup of tea .

and when i came i suddenly saw the error there is mistake of from . i am not using from in my query .
SELECT COUNT(1)  from color

this is silly but happened with me .
Hope this will help you .

ROHIT KUMAR SRIVASTAVA

Thursday 20 September 2012

Query for getting All Primary key and other constraint in SQL SERVER


Select * from  INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk 
 
WHERE pk.CONSTRAINT_TYPE ='PRIMARY KEY' 

Hope this will help you .
Thanks
ROHIT SRIVASTAVA