How to update a row in a particular row [Resolved]

Posted by Mahesh_Chs under Sql Server on 4/24/2012 | Points: 10 | Views : 872 | Status : [Member] | Replies : 3
Hi,

i have created a database in that database i have created the table like

create table emp(id int primary key identity(1,1) ,name varchar(50)) and inserted the values ,now my table contains the id's like 1,2,3,4,5,6 and i have deleted the 3rd row, after deleting the row my id values are 1,2,4,5,6 so how can i write a query to insert the new data into 3 rd row

Thank you,
Mahesh




Responses

Posted by: Jayeshl on: 4/24/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi friend,
thanks to post this query
here is answer for that
i have one category table
with having different values




/****** Object: Table [dbo].[Category] Script Date: 04/24/2012 18:17:25 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Category](
[CategoryID] [int] IDENTITY(1,1) NOT NULL,
[CategoryName] [varchar](50) NULL,
[Description] [varchar](300) NULL,
CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED
(
[CategoryID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

and than i added below values.

INSERT [dbo].[Category] ([CategoryID], [CategoryName], [Description]) VALUES (1, N'Category1', N'Description1')
INSERT [dbo].[Category] ([CategoryID], [CategoryName], [Description]) VALUES (2, N'Category3', N'Description3')
INSERT [dbo].[Category] ([CategoryID], [CategoryName], [Description]) VALUES (3, N'Category3', N'Description3')
INSERT [dbo].[Category] ([CategoryID], [CategoryName], [Description]) VALUES (4, N'Category3', N'Description3')
INSERT [dbo].[Category] ([CategoryID], [CategoryName], [Description]) VALUES (5, N'Category5', N'Description5')

now i want to delete 2nd row with Categoryid = 2
than reinsert value on 2nd row
so please find this for the same

SET IDENTITY_INSERT Category ON
insert into Category ([CategoryID],[CategoryName]
,[Description]) values(2,'Category5','Description5')
SET IDENTITY_INSERT Category OFF

Thanks

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: GSM_GSV on: 4/24/2012 [Member] Starter | Points: 25

Up
0
Down
can you post your DELETE query?

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sunny4989 on: 4/24/2012 [Member] Starter | Points: 25

Up
0
Down
In which position do u want to insert the third record

------------------------------------------------
Learn throughout life

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response