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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query for a staging table

Author  Topic 

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2011-06-18 : 15:02:24
I have 18 monthly tables(Jan 2010 to June 2011) and every month i need to delete the old table(Jan 2010) and need to create a new table July 2011. I think this should be done using dynamic query...can someone shed some light for me on this? I am unable to think about how to write a script which drops the old table and creates a new table.(Everything should be with in one transaction)

Thanks in Advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-18 : 17:08:11
Put everything into a single table and then use table partitioning to split them up. Do some googling/reading on table partitioning.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-18 : 17:13:59
see
http://www.simple-talk.com/sql/database-administration/partitioned-tables-in-sql-server-2005/


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2011-06-18 : 17:17:28
Thanks Tara. But One table does not solve the solution because each time when we delete the data, i may need to drop the field group and create one(The table structure is in that way). The easiest way is to drop the old table and create a new table with in the transaction.

Also even table partitioning needs similar kind of query where i may need to drop the old data(Field group) and need to insert data in the new Field group.

I am having hard time to build a dynamic query which does all the operation with in a single transaction. Need some help in here.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-18 : 18:08:44
Table partitioning is the way to go here.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -