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 |
|
xpandre
Posting Yak Master
212 Posts |
Posted - 2002-01-31 : 11:04:10
|
| Hi guys,How do i create a new table similar to an existing one in the database?eg:i have t1 as id intidref inti want to create a new table t2 at run time exactly similar to t1 assuming i dont know the construct of t1..Thank yousam |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-01-31 : 11:25:12
|
| SELECT * INTO t2 FROM t1Be careful of doing this with large tables, it can use up a lot of resources and may cause performance issues. Also, this won't carry over indexes or constraints from the t1 table. |
 |
|
|
xpandre
Posting Yak Master
212 Posts |
Posted - 2002-01-31 : 11:27:40
|
| THAT WAS TOOO FAST AND TOOO KEWL robvolk....THANX A MILLIONSAM |
 |
|
|
xpandre
Posting Yak Master
212 Posts |
Posted - 2002-01-31 : 11:32:15
|
| i used thisSELECT TOP 1 * INTO TEST3 FROM TEST1and it worked :dThanx again robvolkSam |
 |
|
|
xpandre
Posting Yak Master
212 Posts |
Posted - 2002-01-31 : 12:11:47
|
| CAN I USE THIS IN a procedure?thank you sam |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-01-31 : 12:37:40
|
| Absolutely, just put a CREATE PROCEDURE in front of it:CREATE PROCEDURE Top1 ASSELECT TOP 1 * INTO TEST3 FROM TEST1SELECT * FROM Test3DROP TABLE Test3The 2nd line will return the results from the newly created table. The DROP TABLE is optional, but if this new table is not meant to be a permanent one you should keep it in there. |
 |
|
|
jbkayne
Posting Yak Master
100 Posts |
Posted - 2002-01-31 : 12:54:08
|
You could improve on this:SELECT * INTO TEST3 FROM TEST1 WHERE 1=2this would result in the table structure and 0 rowsquote: i used thisSELECT TOP 1 * INTO TEST3 FROM TEST1and it worked :dThanx again robvolkSam
|
 |
|
|
|
|
|