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 2000 Forums
 SQL Server Administration (2000)
 Truncate table everytime SQL Service restarts

Author  Topic 

Sini
Starting Member

18 Posts

Posted - 2007-08-14 : 09:06:07
Hello

I need to truncate a table everytime the SQL service restarts - can anyone help?

Thanks.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-14 : 10:05:55
exec sp_procoption N'YourStoredProcedure', 'startup', 'on'

and you truncate the tables in your YourStoredProcedure


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Sini
Starting Member

18 Posts

Posted - 2007-08-14 : 10:07:02
Thanks for the swift reply - im gonna give it a try.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-14 : 10:10:05
note that this sproc must be owned by dbo and reside in master database

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Sini
Starting Member

18 Posts

Posted - 2007-08-14 : 10:56:40
I created it in the master database - but how do i get it to truncate a table that resides in another database?

I cant get a USE <databasename> to work in a create stored proc.

Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-08-14 : 11:15:56
truncate table dbName.OwnerName.tableName

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Sini
Starting Member

18 Posts

Posted - 2007-08-14 : 11:20:06
Thanks.
Go to Top of Page
   

- Advertisement -