Sunday, 27 August 2017

SQL Query

ROW_NUMBER()

--Use of row_number() function
select row_number() over (order by id) as row,id from alltable

Pivot

-- Use of Pivot key word
select id,stu_name,address,qualification from t1 pivot(min(value) for attribute in(stu_name,address,qualification)) t

To show Duplicate Records

--Create table

create table dup(id int,name nvarchar(50),age int)

--Insert Records

insert into dup(id,name,age) values(1,'ramu',23),(1,'ramu',23),(2,'Shachi',30),(2,'Shachi',30),(3,'rahul gupta',20),(3,'rahul gupta',20)

--Sql Query for find duplicate data in Sql Server

select id,name,age, count(*) from dup group by id,name,age having count(*) > 1
--Sql Query for Delete Duplicate Record

delete from dup where dup.%%physloc%% NOT IN (select MIN(b.%%physloc%%) fromdup b group by b.id,b.name,b.age )


BACKUP DATABASE Ramu_db TO DISK = 'D:\Ramu_db.bak' WITH INIT
where Ramu_db is data base name and Ramu_db.bak' is database backup file name with drive location.

No comments:

Post a Comment

React Hooks - custom Hook

  v CustomHook Ø React allows us to create our own hook which is known as custom hook. Example – 1 localStorage Demo Step-1 Create ...