pnmhtkr
pnmhtkr

Reputation: 53

How to insert record in existing column using SQL Server

create table tbl1(rno int, name varchar(10))
insert into tbl1 values(101, 'neha')

alter table tbl1 add city varchar(10)
select * from tbl1

In this code, I am inserting a record into city column. I tried following code too, but this not proper code need help to add a record.

insert into tbl1 (city) 
    SELECT CITY  
    FROM tbl1  
    WHERE rno = 1

update tbl1 
set city = 'pune' 
where rno = 1;

2nd query is returning "0 records updated" ans.

Upvotes: 1

Views: 390

Answers (1)

marc_s
marc_s

Reputation: 754438

The row that you inserted into your table has rno = 101 - so your UPDATE statement must look like this:

update tbl1 
set city = 'pune' 
where rno = 101;   -- use **101** here - not **1** !!

Upvotes: 1

Related Questions