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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With