这是插入方式,选择通常是有效的 (例子来自:https://stackoverflow.com/a/576442/101055):
INSERT INTO new_table (Foo, Bar, Fizz, Buzz)
SELECT Foo, Bar, Fizz, Buzz
FROM initial_table
但是 - 如果Fizz
不在initial_table中,但是变量为@fizz
,该如何执行此操作?
此失败:
INSERT INTO new_table (Foo, Bar, @fizz, Buzz)
SELECT Foo, Bar, Buzz
FROM initial_table
日Thnx
答案 0 :(得分:2)
INSERT INTO new_table (Foo, Bar, Fizz, Buzz)
SELECT Foo, Bar, @fizz, Buzz
FROM initial_table
插入语法是
insert into destination_table (destination_colum1, destination_colum2, ...)
select source_value1, source_value2, ... from source_table
首先,您要将要写入的列命名为,然后选择源