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.
Author |
Topic |
Loneliness
Starting Member
10 Posts |
Posted - 2013-09-27 : 06:16:18
|
Hello, i need to create a table selecting from a view:select *into Mytablefrom Myviewbut i want Mytable to have an IDENTITY column that is not present in Myview...can i achieve this directly in the select statement without altering the table afterwards?Tank you. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-09-27 : 08:08:03
|
You can. Example:SELECT *,IDENTITY(INT,1,1) As NewColumnINTO MyTableFROM MyView See documentation here: http://technet.microsoft.com/en-us/library/ms189838.aspx |
|
|
Loneliness
Starting Member
10 Posts |
Posted - 2013-09-27 : 08:25:23
|
Thank you very much James. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-09-28 : 04:36:14
|
if you want identity values to be generated based on order of particular column make sure you use something likeSELECT *,ROW_NUMBER() OVER (ORDER BY YourColumn ) As NewColumnINTO MyTableFROM MyView SELECT INTO with IDENTITY will not guarantee the order in which identity values are generatedhttp://support.microsoft.com/kb/273586------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Loneliness
Starting Member
10 Posts |
Posted - 2013-10-02 : 05:25:53
|
Thanx visakh16. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-04 : 01:29:40
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2013-10-08 : 08:52:13
|
Why do you want to create a new table? Can't you do it when selecting data from view?SELECT *,ROW_NUMBER() OVER (ORDER BY YourColumn ) As NewColumnFROM MyViewMadhivananFailing to plan is Planning to fail |
|
|
|
|
|