Create Table from View

2020-02-07 15:49发布

I have a view that I want to create a table from in SQL Enterprise Manager, but I always get an error when I run this query:

CREATE TABLE A 
AS
(SELECT top 10 FROM dbo.myView)

So far the error is: "syntax error at 'as'"

View is too large. Is it possible to use a top 10?

标签: sql tsql view
9条回答
The star\"
2楼-- · 2020-02-07 16:28

Looks a lot like Oracle, but that doesn't work on SQL Server.

You can, instead, adopt the following syntax...

SELECT
  *
INTO
  new_table
FROM
  old_source(s)
查看更多
趁早两清
3楼-- · 2020-02-07 16:31

If you just want to snag the schema and make an empty table out of it, use a false predicate, like so:

SELECT * INTO myNewTable FROM myView WHERE 1=2
查看更多
乱世女痞
4楼-- · 2020-02-07 16:36
Select 
    MonthEndDate MED,  
    SUM(GrossBalance/1000000) GrossBalance,
    PortfolioRename PR 
into 
    testDynamic 
from 
    Risk_PortfolioOverview  
    Group By MonthEndDate, PortfolioRename
查看更多
我欲成王,谁敢阻挡
5楼-- · 2020-02-07 16:37

In SQL SERVER you do it like this:

SELECT *
INTO A
FROM dbo.myView

This will create a new table A with the contents of your view.
See here for more info.

查看更多
再贱就再见
6楼-- · 2020-02-07 16:39

INSERT INTO table 2 SELECT * FROM table1/view1

查看更多
Juvenile、少年°
7楼-- · 2020-02-07 16:46

To create a table on the fly us this syntax:

SELECT *
INTO A
FROM dbo.myView
查看更多
登录 后发表回答