Friday, 18 July 2014

Sql query of create,check,Distinct and order by.


Check that Table is exist in current database or not.

SELECT * FROM "+x+" WHERE 1 = 0

Create new Table.

 "create table " + x + " (" + "name nvarchar(50)," + "gender nvarchar(50)," + "email nvarchar(50)," + "mobile nvarchar(50))";

 Check the person should be major using CHECK keyword.

create table test1
(
 name varchar(50) not null ,
 age int NOT NULL CHECK (age >=18)
)

Check condition using AND keyword.

select * from atim where eid='123' AND dtim ='00:00:27'

Check condition using OR keyword.

select * from atim where eid='123' OR dtim ='00:00:27'

Show data in Desecending order.

select * from atim ORDER BY eid desc

Show data in Asecending order.

select * from atim ORDER BY eid asec

Show data in case order (own order).

select * from atim ORDER BY (case eid when 123 then 1
when 321 then 2
 else 100 end )

Show data in unrepeated form.

 select DISTINCT eid from atim ORDER BY eid



No comments:

Post a Comment