为什么我不能使用简单的查询CREATE TABLE创建新表格?

huangapple go评论109阅读模式
英文:

Why I can't create a new table using simply query CREATE TABLE?

问题

MS SQL SERVER
当我执行查询

  1. SELECT *
  2. FROM dbo.transactions

它会完美地列出所有行和列。

问题是当我尝试使用 CREATE TABLE 创建新表时

  1. CREATE TABLE dbo.all_transactions
  2. SELECT *
  3. FROM dbo.transactions

或者

  1. CREATE TABLE dbo.all_transactions AS
  2. SELECT *
  3. FROM dbo.transactions

我总是得到一个奇怪的错误

  1. Msg 156, Level 15, State 1, Line 2
  2. 关键字 'SELECT' 附近的语法不正确

只有 * 在 SELECT 旁边。它怎么可能是“语法不正确”?

我尝试更改表名或使用另一个表,但它不起作用。
我检查了列的名称是唯一的。它们是唯一的。

英文:

MS SQL SERVER
When I do query

  1. SELECT *
  2. FROM dbo.transactions

it list all rows and colums perfectly.

Problem is when I'm trying to do a new table with CREATE TABLE

  1. CREATE TABLE dbo.all_transactions
  2. SELECT *
  3. FROM dbo.transactions

or

  1. CREATE TABLE dbo.all_transactions AS
  2. SELECT *
  3. FROM dbo.transactions

Always I get strange error

  1. Msg 156, Level 15, State 1, Line 2
  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:

  1. SELECT * INTO dbo.all_transactions
  2. FROM dbo.transactions;

huangapple
  • 本文由 发表于 2023年3月31日 23:28:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75900251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定