Create Table from View

后端 未结 9 2110
一整个雨季
一整个雨季 2020-12-12 19:08

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 1         


        
相关标签:
9条回答
  • 2020-12-12 19:30

    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
    
    0 讨论(0)
  • 2020-12-12 19:34
    SELECT * INTO [table_a] FROM dbo.myView
    
    0 讨论(0)
  • 2020-12-12 19:36

    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)
    
    0 讨论(0)
  • 2020-12-12 19:38

    SQL Server does not support CREATE TABLE AS SELECT.

    Use this:

    SELECT  *
    INTO    A
    FROM    myview
    

    or

    SELECT  TOP 10
            *
    INTO    A
    FROM    myview
    ORDER BY
            id
    
    0 讨论(0)
  • 2020-12-12 19:49

    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.

    0 讨论(0)
  • 2020-12-12 19:51

    To create a table on the fly us this syntax:

    SELECT *
    INTO A
    FROM dbo.myView
    
    0 讨论(0)
提交回复
热议问题