Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to delete contents of a MSDE Database Table

Status
Not open for further replies.

steveot

IS-IT--Management
Joined
Oct 27, 2003
Messages
1,635
Location
US
I not a SQL expert but was wondering if somebody could help me out. I need a script that can delete or emtpy the contents of three tables in a database running on msde. Enterprise manager will not be available naturally. So I assume and osql script will be the option.

Basically I got stuck but here is what I need:

to empty a table or clear the contents of a table..not delete


servername\sqlinstancename databasename table1
servername\sqlinstancename databasename table2
servername\sqlinstancename databasename table3
 
There are 2 ways...

Truncate Table <TableName>

or

Delete From <TableName>

Truncate is faster because the data you are removing from the table is not logged.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Any suggestion on a script for this or how to write it?
 
You can use oSql to accomplish this. Here's the command line you'll need.

osql -S servername\sqlinstancename -d databasename -U UserName -P Password -Q "Truncate Table Table1"

Replace items in bold with your specifics. Hope this helps.



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top