1
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.

3
  • from which column do you want to update city? is it in same table? Commented Nov 28, 2016 at 5:03
  • is there is any record found for rno =1 ? i think no records found so the update not works... Commented Nov 28, 2016 at 5:04
  • The 2nd query isn't updating anything because your row in the table has rno = 101 - not rno = 1 ...... Commented Nov 28, 2016 at 5:13

1 Answer 1

1

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** !!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.