Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to insert table city name like chennai and newly update delhi both rows maintain
in sql server ?

Thanks Advance,
Posted
Comments
Zoltán Zörgő 28-Sep-15 7:06am    
And....? What is stopping ypu in doing so? What have you tried so far?
Please improve your question.
Naveen.Sanagasetti 28-Sep-15 7:12am    
What's the issue..

My suggestion fro this is put an flag in table like IsActive Based on flag you can do the updation means when the flag value is 1 then insert new row into the Table and update the old row flag value to 0.

Ex:
Insert into table(city ,Isactive)
values('New City',1)
update table set Isactive=0 where city='old city' and ID='Old City ID'
 
Share this answer
 
you can do this
for Adding New Columns
Syntax:
ALTER TABLE <table_name>;
ADD (<newcolumnname><data_type(><size>)
 
Share this answer
 
How to write query or stored procedure for this situation
 
Share this answer
 
Comments
vangapally Naveen Kumar 29-Sep-15 1:24am    
please ask in questions section :)
Any how you can write stored procedure for this situation based on the 'Old City ID'
SQL
Create Proc ProcName
AS
BEGIN
@aOLDCITYID INT

IF ISNULL(@aOLDCITYID,0) <>0
BEGIN
   Insert into table(city ,Isactive)
    values('New City',1)
    update table set Isactive=0 where city='old city' and ID='Old City   ID'
  

END
Else
Begin
  Print 'Hello'
End
END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900