Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Table from View

Tags:

sql

tsql

view

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?

like image 864
tdjfdjdj Avatar asked Jul 14 '11 14:07

tdjfdjdj


People also ask

Can you create a table from a view?

Now, a view is just like a virtual table. So, we can also use view to create a table without even using CREATE TABLE statement. Let's, understand the syntax of this implementation, and then we will execute an example. In the above syntax, first, we have to use the SELECT statement to select the required columns.

How do you get a table from a view?

CREATE TABLE yourTableName AS SELECT yourColumnName1,yourColumnName2,yourColumnName3,........ N from yourViewName; To run the above query, first you need to create a table and after that you need to create a view on that table. After that run the query.

Can we create a table from a view in MySQL?

You can do CREATE TABLE SELECT from the view to build it. That should duplicate the view's structure as a new table containing all the view's rows.

How do I create a multiple table from a view?

You can create a view that combines data from two or more tables by naming more than one table in the FROM clause. In the following example procedure, the INVENTORY_LIST table contains a column of item numbers called ITEM_NUMBER and a column of item cost called UNIT_COST.


1 Answers

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 
like image 121
Quassnoi Avatar answered Oct 14 '22 00:10

Quassnoi