sql - alter table then update in single statement -
i have requirement need alter (add 2 columns) , update same table.
here query tried:
alter table add c1 int,c2 varchar(10) update set c1 = 23, c2 = 'zzxx'
i need run above 2 queries @ time.
i using talend etl tool, in have component tmssqlrow, allow run multiple queries (i using 10 15 update queries in single component).
but above query not working.
i tested in database microsoft sql. getting below error :
msg 207, level 16, state 1, line 5
invalid column name 'c1'. msg 207,
level 16, state 1, line 5
invalid column name 'c2'.
can 1 me resolve problem.
you can't exactly in single statement (or batch) , seems tool using not support go
batch delimiter.
you can use exec
run in child batch though.
alter table add c1 int, c2 varchar(10); exec(' update set c1 = 23, c2 = ''zzxx''; ');
nb: single quotes in query need doubled above escape them inside string literal.
or alternatively achieve similar results in single statement aid of default constraints.
alter table add c1 int null constraint df_a_c1 default 23 values, c2 varchar(10) constraint df_a_c2 null default 'zzxx' values;
but not same original query default constraints left behind , may need dropped.
Comments
Post a Comment