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 |
|
jlrajan
Starting Member
6 Posts |
Posted - 2004-12-01 : 16:00:02
|
| Hi,I am writing a Stored Procedure in which I need to archive records which are older than a certain period every month. Since the records are only from 2 tables, I am writing them into flat files. I also need to store the table scripts alongwith these flat files in order to load them as and when necessary. Could you let me know how to generate a CREATE TABLE script for a table from within a Stored Procedure? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-12-01 : 16:11:48
|
| You would just write it, no need to generate it for just two tables:CREATE TABLE Table1( Column1 varchar(50) NOT NULL, Column2 int NOT NULL, ...)Syntax of CREATE TABLE can be found in SQL Server Books Online.Tara |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-12-01 : 16:14:00
|
well sql uses following sprocs to generate sql scripts:exec sp_MShelpcolumns N'[dbo].[orders]', 512, @orderby = 'id'exec sp_MStablekeys N'[dbo].[orders]', null, 6exec sp_MShelpindex N'[dbo].[orders]'exec sp_MShelpcolumns N'[dbo].[orders]', @orderby = 'id'exec sp_dbcmptlevel N'Northwind'exec sp_MStablekeys N'[dbo].[orders]', null, 6exec sp_MStablechecks N'[dbo].[orders]'exec sp_MShelpindex N'[dbo].[orders]'exec sp_MStablekeys N'[dbo].[orders]', null, 8but those are all undocumented sprocs so don't use them in production enviromentGo with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|
|
|