I needed to write a SQL command that will populate a new column that has just been introduced into a table but spent quite some time figuring how to do that using the INSERT INTO SQL statement. Instead of thinking about INSERT INTO, what was needed in this scenario is the UPDATE syntax.
INSERT INTO
Insert new rows. Can also do updates if a unique key duplicate has been found and thus can be updated through:
INSERT INTO tablename ON DUPLICATE KEY UPDATE columnName1='newValue1', columnName2='newValue2'...
UPDATE
To update pre-existing rows. Exampl:
UPDATE tablename set columnName = 'newValue'
Advertisements
Leave a Reply