Question

I can't really think of the best way to phrase this question, so I'll just give an example. Suppose I have a table that is created like this:

CREATE VIEW People
AS
    SELECT
        id, --int
        name, --varchar(20)
        birthdate --datetime
    FROM SomeTable

If I wanted to change this from a view to a physical table, is there any way to create a table with the same layout?

In other words, I want to take that view and create a table like this:

CREATE TABLE People(
    id int,
    name varchar(20),
    birtdate datetime
)

...but without having to manually write that query out.

This is of course a contrived example. The view has a lot of fields with a lot of different data types, so it would be difficult to do by hand.

Was it helpful?

Solution

How about

SELECT * INTO MyNewTable FROM MyView 

AND if you don't want the content, just the structure

SELECT * INTO MyNewTable FROM MyView WHERE 1 = 2

OTHER TIPS

SELECT *
INTO People_Table
FROM People_View

Select * INTO PeopleTable FROM People

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top