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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncate a SQL table with JS

Status
Not open for further replies.

rosn459

Programmer
Sep 18, 2003
37
US
Can I truncate a SQL table with Javascript? I've tried:
<script language = "Javascript">
function TableReset
{
strSQL = "Truncate Table tblname";
}

</script>
 
I'm not sure what you want to do. Can you be more specific?

There's always a better way. The fun is trying to find it!
 
I am trying to truncate a SQL table.

I insert records into the table and when I'm finished with manipulating the data, I need to truncate the table to delete all the records and reset the autonumber field. I want to use the Truncate Table command because one of my SQL columns is an autonumber column.
 
You can't access a SQL database/table from Javascript client-side in a web browser. You may be able to find an ActiveX control to do this... but that's going to be a solution that will lock out all non-Windows, non-IE users.

Since you have said you are using SQL, why not write a stored procedure that "truncates" the table as part of an "initialisation" process? Be aware, that if you do this, then how will you deal with multiple users performing the task simultaneously?

Jeff
 
Jeff,

Thanks for validating my suspicions. I thought there might be a "creative" way to do this and wanted to verify there wasn't. I thought since one could insert and update records into a SQL table one could also truncate the table.

I'll explore using a temp table instead. That might resolve the multiple user issue.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top