英文:
Why I can't create a new table using simply query CREATE TABLE?
问题
MS SQL SERVER
当我执行查询
SELECT *
FROM dbo.transactions
它会完美地列出所有行和列。
问题是当我尝试使用 CREATE TABLE 创建新表时
CREATE TABLE dbo.all_transactions
SELECT *
FROM dbo.transactions
或者
CREATE TABLE dbo.all_transactions AS
SELECT *
FROM dbo.transactions
我总是得到一个奇怪的错误
Msg 156, Level 15, State 1, Line 2
关键字 'SELECT' 附近的语法不正确
只有 * 在 SELECT 旁边。它怎么可能是“语法不正确”?
我尝试更改表名或使用另一个表,但它不起作用。
我检查了列的名称是唯一的。它们是唯一的。
英文:
MS SQL SERVER
When I do query
SELECT *
FROM dbo.transactions
it list all rows and colums perfectly.
Problem is when I'm trying to do a new table with CREATE TABLE
CREATE TABLE dbo.all_transactions
SELECT *
FROM dbo.transactions
or
CREATE TABLE dbo.all_transactions AS
SELECT *
FROM dbo.transactions
Always I get strange error
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'
There is only * next to SELECT. How it could be an "Incorrect syntax"?
I tried changing the table name or using another table, but it doesn't work.
I checked the names of the columns are unique. They are unique.
答案1
得分: 2
SELECT * INTO dbo.all_transactions
FROM dbo.transactions;
英文:
Suppose you want to create table all_transactions
copying the data from transactions
Try out this:
SELECT * INTO dbo.all_transactions
FROM dbo.transactions;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论