I have a column1 that currently matches everything in another column2 in that same table. I now need the column1 to automatically update when I add a new row and fill in column2. This is in SQL.
I was thinking
ALTER TABLE dbo.Table
alter column column1 as column2
might work, but it appears not.
Is it possible to do this with something along the lines of an alter statement (ie. without a trigger)?
You can use a TRIGGER to automatically update Column2 whenever Column1 changes:
You can also make Column2 a computed column:
If you always want the two to be in sync, I’d suggest just removing your existing column and added in a new computed column with the same name.
A third way would be to create a VIEW that simply exposes Column1 twice: