Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 converting view to a table

Author  Topic 

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 07:36:40
Hi,

I have a view and want to convert it to a table using stored procedure?

is that possible?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 07:39:58
what do you mean "convert it to a table" ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 07:41:44
I have a view and want to put it in a table so my page will call that? is that possible
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 07:47:43
why do you need to do that ? view is like a table. You can SELECT from it the same way as you are SELECTing from a table.




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 07:49:34
for greater performance of my page..my view consists of formula..so I want to have another table getting those results using stored procedure
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-07-30 : 07:52:59
select * into your_table from your_view

But why you want to make it as a table? You can do what ever on table in view also.

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 07:54:22
if you are going to do that, you will need to update this table whenever the any of the base table of the view changes. Is this what you want ?

a quick way to create the table out of view is


select * into new_table from theview


after that, create the necessary indexes on the table


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 07:56:24
it's not that...the view is automatically being updated and computed..I want that view to have another table..i've read about alter..i don't know how
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 07:58:54
quote:
Originally posted by BankOfficerHere

it's not that...the view is automatically being updated and computed..I want that view to have another table..i've read about alter..i don't know how



You want to include another table into the view query ?

You want to join another table to the view ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 08:01:42
no, i want my view results be transfered to another new table
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 08:05:00
quote:
Originally posted by BankOfficerHere

no, i want my view results be transfered to another new table



that is what "select * into new_table from myview" doing.



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 08:09:29
it looks like this:

alter proc
zz_test1

as

insert into [database].[dbo].[table]
Go to Top of Page

BankOfficerHere
Posting Yak Master

124 Posts

Posted - 2009-07-30 : 08:11:17
also I don't want a new table..just an existing table
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-30 : 08:11:42
[code]
insert into [database].[dbo].[table] ( < column list > )
select < column list >
from your_view
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

craigwg
Posting Yak Master

154 Posts

Posted - 2009-07-30 : 10:56:12
Views are created from tables, right? So why go from table to view to table. Just create a table from the tables you are currently using to create the view. Take out the middle man. I'm not suggesting to delete the view of course, but seems more straight forward to me!


Craig Greenwood
Go to Top of Page
   

- Advertisement -