Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

sql - add not null column take values from other column

-- add the column (as nullable)
alter table mytable add created_year int;

-- update the values on existing rows
update items set created_year = year(created_date);

-- make the column not nullable
alter table mytable alter column created_year int not null;
Source by sqlerrors.com #
 
PREVIOUS NEXT
Tagged: #sql #add #null #column #values #column
ADD COMMENT
Topic
Name
9+6 =