无法识别语法错误

时间:2015-02-27 02:25:43

标签: sql sql-server

新手在这里。我试图在sql server中执行这一行:

  

CREATE TABLE dummy_driver

但我在 附近收到错误消息 语法错误。我无法找到错误。

附加代码行:

INSERT INTO Person (first_name, last_name)
Select f_name, l_name FROM driver;

CREATE TABLE dummy_driver

INSERT INTO dummy_driver
Select * from driver;

3 个答案:

答案 0 :(得分:5)

您需要在Create语句中为表定义列。您的TSQL应如下所示:

INSERT INTO Person (first_name, last_name)
Select f_name, l_name FROM driver;

CREATE TABLE dummy_driver (First_Name varchar(25), last_name varchar(25))

INSERT INTO dummy_driver
Select first_name, last_name from driver;

您还可以使用Select Into

动态创建表格
SELECT first_name, last_name into dummy_driver
FROM driver

答案 1 :(得分:0)

我可以看到您希望将整个架构和数据从driver复制到dummy_driver。您可以简单地写为:

,而不是为Create Table编写dummy_driver语句
SELECT * INTO dummy_driver FROM driver

答案 2 :(得分:-1)

如果您只是从driver选择所有列到dummy_driver,您也可以像这样创建:

create table dummy_driver like driver;

insert into dummy_driver select * from driver;