473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

DROP TABLE vs DoCmd.DeleteObject acTable

My client has a db I am working that uses temp tables. During an
update procedure, I had the code If fTableExists(tempTblName) = True
Then DoCmd.DeleteObject acTable, tempTblName

Then I thought of using: If fTableExists(tempTblName) = True Then
CurrentDb.Execute "DROP TABLE " & tempTblName

Is there an advantage to either? What really be cool is DROP TABLE
deleted the table and I didn't have to compact the db so much.


Aug 21 '08 #1
10 49568
even cooler would be to use a temp db, with the tables linked into the data
db. that way you never add or delete table objects in the data db - instead
you just overwrite the temp db with a fresh copy as needed.

hth
"Dean" <no*****@coveyaccounting.comwrote in message
news:00**********************************@l64g2000 hse.googlegroups.com...
My client has a db I am working that uses temp tables. During an
update procedure, I had the code If fTableExists(tempTblName) = True
Then DoCmd.DeleteObject acTable, tempTblName

Then I thought of using: If fTableExists(tempTblName) = True Then
CurrentDb.Execute "DROP TABLE " & tempTblName

Is there an advantage to either? What really be cool is DROP TABLE
deleted the table and I didn't have to compact the db so much.


Aug 21 '08 #2
On Aug 21, 6:05*am, Dean <nore...@coveyaccounting.comwrote:
My client has a db I am working that uses temp tables. *During an
update procedure, I had the code If fTableExists(tempTblName) = True
Then DoCmd.DeleteObject acTable, tempTblName

Then I thought of using: If fTableExists(tempTblName) = True Then
CurrentDb.Execute "DROP TABLE " & tempTblName

Is there an advantage to either? *What really be cool is DROP TABLE
deleted the table and I didn't have to compact the db so much.

I did fund the followsin the the help:
"Deleting a table is faster when you use the SQL DROP statement or the
SQL DELETE statement without a predicate."
Aug 21 '08 #3
Yes. If it's a cloudy day the SQL DROP statement can trash a table in
1.6 one thousandths of a second (16/10000 seconds) faster than DoCmd
DELETE. Just think, after ten thousand deletions we could save 16
seconds! Well it's measurably faster only about 1/4 of the time, so I
guess that would be four seconds saved in 10000 deletions. WooHoo!
Ain't Access Help grand! Not only that but when we read something in
Access Help we can feel confident that there is a 50% chance that it's
correct (and a further 25% chance that it's complete)! That's pretty
good if you compare it with a Stevie Harper speech!

But I'm still trying to understand why you think DROP Table (as
opposed to DoCmd.Delete) might reduce the need to compact. I guess
I'll use my four seconds to think about that.

BTW, in my use of Access since the early nineties I do not recall ever
using a temporary table that was saved to disk. I like it that way.

On Aug 21, 5:37*pm, Dean <nore...@coveyaccounting.comwrote:
I did fund the followsin the the help:
"Deleting a table is faster when you use the SQL DROP statement or the
SQL DELETE statement without a predicate."
Aug 22 '08 #4
"lyle fairfield" <ly************@gmail.comwrote in message
news:83**********************************@l64g2000 hse.googlegroups.com...
Yes. If it's a cloudy day the SQL DROP statement can trash a table in
1.6 one thousandths of a second (16/10000 seconds) faster than DoCmd
DELETE. Just think, after ten thousand deletions we could save 16
seconds! Well it's measurably faster only about 1/4 of the time, so I
guess that would be four seconds saved in 10000 deletions. WooHoo!
Ain't Access Help grand! Not only that but when we read something in
Access Help we can feel confident that there is a 50% chance that it's
correct (and a further 25% chance that it's complete)! That's pretty
good if you compare it with a Stevie Harper speech!

But I'm still trying to understand why you think DROP Table (as
opposed to DoCmd.Delete) might reduce the need to compact. I guess
I'll use my four seconds to think about that.

BTW, in my use of Access since the early nineties I do not recall ever
using a temporary table that was saved to disk. I like it that way.

On Aug 21, 5:37 pm, Dean <nore...@coveyaccounting.comwrote:
I did fund the followsin the the help:
"Deleting a table is faster when you use the SQL DROP statement or the
SQL DELETE statement without a predicate."
To the OP,
When I use temp tables, I usually create them with a Make-Table Query. By
default, it automatically overwrites the existing table if it's there. When
done via code, I use the following if I want to make it seamless to the
user:

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryMakeTable"
DoCmd.SetWarnings True

Fred Zuckerman
Aug 22 '08 #5
>
But I'm still trying to understand why you think DROP Table (as
opposed to DoCmd.Delete) might reduce the need to compact. I guess
I'll use my four seconds to think about that.

I have been using Access since 2.0. I didn't really think it would
reduce the need to compact a database...just thought it'd be cool
feature MS should look at. But the help documentation sheds little
light on the differences between the two commands. Just curios if
anyone knew.
Aug 22 '08 #6
On Aug 21, 11:07*pm, "Fred Zuckerman" <Zuckerm...@sbcglobal.net>
wrote:
"lyle fairfield" <lyle.fairfi...@gmail.comwrote in message
To the OP,
When I use temp tables, I usually create them with a Make-Table Query. By
default, it automatically overwrites the existing table if it's there. When
done via code, I use the following if I want to make it seamless to the
user:

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryMakeTable"
DoCmd.SetWarnings True

Fred Zuckerman
These temp tables (22 in all) my client makes is from an ODBC
connection to their ERP system. Not sure why he went this route
though. He deletes and imports with the database transfer command.
This method works, but bloats the db each time import which is at
least daily. So nothing like a qryMakeTable will fit here.

Aug 22 '08 #7

"Dean" <no*****@coveyaccounting.comwrote in message
news:f7**********************************@x41g2000 hsb.googlegroups.com...
On Aug 21, 11:07 pm, "Fred Zuckerman" <Zuckerm...@sbcglobal.net>
wrote:
>"lyle fairfield" <lyle.fairfi...@gmail.comwrote in message
>To the OP,
When I use temp tables, I usually create them with a Make-Table Query. By
default, it automatically overwrites the existing table if it's there.
When
done via code, I use the following if I want to make it seamless to the
user:

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryMakeTable"
DoCmd.SetWarnings True

Fred Zuckerman

These temp tables (22 in all) my client makes is from an ODBC
connection to their ERP system. Not sure why he went this route
though. He deletes and imports with the database transfer command.
This method works, but bloats the db each time import which is at
least daily. So nothing like a qryMakeTable will fit here.
---------------------------------------------------------------------------------

What about a delete query (delete all records) followed by an append query?
That saves having to remove and add objects.
I don't know if that minimizes bloat.....
Fred Zuckerman
Aug 22 '08 #8
On Aug 21, 11:50*pm, "Fred Zuckerman" <Zuckerm...@sbcglobal.net>
wrote:
"Dean" <nore...@coveyaccounting.comwrote in message

news:f7**********************************@x41g2000 hsb.googlegroups.com...
On Aug 21, 11:07 pm, "Fred Zuckerman" <Zuckerm...@sbcglobal.net>
wrote:


"lyle fairfield" <lyle.fairfi...@gmail.comwrote in message
To the OP,
When I use temp tables, I usually create them with a Make-Table Query.By
default, it automatically overwrites the existing table if it's there.
When
done via code, I use the following if I want to make it seamless to the
user:
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryMakeTable"
DoCmd.SetWarnings True
Fred Zuckerman
These temp tables (22 in all) my client makes is from an ODBC
connection to their ERP system. *Not sure why he *went this route
though. *He deletes and imports with the database transfer command.
This method works, but bloats the db each time import which is at
least daily. *So nothing like a qryMakeTable will fit here.

---------------------------------------------------------------------------*------

What about a delete query (delete all records) followed by an append query?
That saves having to remove and add objects.
I don't know if that minimizes bloat.....
Fred Zuckerman- Hide quoted text -

- Show quoted text -
The data is imported database transfer command. So yes, you could
link the odbc tables then write your own delete/append but you have to
do this 22 times. Also, each o connection consumes a license on their
ERP software so a live connection should be avoided on a multi-user
db. For the purpose of the Access db they created, there is no need
for it to be live anyway.
The list of the ODBC tables needed are stored in a table and it loops
through the list:
If fTableExists(tempTblName) = True Then
CurrentDb.Execute "DROP TABLE " & tempTblName
docmd.transferdatabase tempTblName, "ODBC Connection"
etc.

If a new table is needed, just add it to the list of tables. Run the
procedure. So the code is pretty efficient and easy to maintain.

None of this answers the real question I asked:

DoCmd.DeleteObject acTable, tempTblName
or
CurrentDb.Execute "DROP TABLE " & tempTblName

Is there an advantage to either other than the little blurb I found in
help?
It seems I gave too much detail.
Aug 22 '08 #9
---------------------------------------------------------------------------*------

What about a delete query (delete all records) followed by an append query?
That saves having to remove and add objects.
I don't know if that minimizes bloat.....
Fred Zuckerman- Hide quoted text -

- Show quoted text -
No way that minimizes any bloat. A deleted record or object is still
there until you compact.
Aug 22 '08 #10
On Aug 22, 6:28*am, Dean <nore...@coveyaccounting.comwrote:
None of this answers the real question I asked:

DoCmd.DeleteObject acTable, tempTblName
or
CurrentDb.Execute "DROP TABLE " & tempTblName

Is there an advantage to either other than the little blurb I found in
help?
My guess is that either the 'DoCmd.DeleteObject acTable, tempTblName'
is implemented by using a 'DROP TABLE ...' query, or the 'DROP
TABLE...' query is implemented by changing the Object Model. The hint
that the 'DROP TABLE...' query is slightly faster makes me lean toward
the former. Either implementation would have to deal with the table
object eventually without the expense of having to look at the rest of
the Object Model. An example of an Access Object Model:

http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

But all this is just guesswork at what Access does under the hood.
Sometimes I am amazed at how simple the implementation is to many
things that Microsoft tried so hard to make look like it took a lot of
effort. Other times they surprise me by getting the implementation
right for some truly difficult things. I suppose I would implement
the 'DROP TABLE' SQL by having it modify the Object Model and having
the DoCmd.DeleteObject do likewise. Therefore my best guess is that
Microsoft implements both with 'DROP TABLE' :-).

James A. Fortune
CD********@FortuneJames.com
Aug 25 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed | last post by:
I am trying to get some information to compare and contrast the Truncate Table function and the Drop Table function. I know that using Truncate Table is faster and saves the structure of the table...
5
by: Eric Freeman | last post by:
I'm trying to drop a table and it's taking a very long time. There has been a lot of modification to the table and it has a lot of old data still being used as a result of not using the vacuum...
14
by: deko | last post by:
Can the DROP TABLE statement be used with a select or where statement? DROP TABLE SELECT * FROM tblTablesImported WHERE Import_ID Not In (SELECT FROM tblTablesInternal); Or do I have to...
10
by: Geoff Jones | last post by:
Hi I'm trying to drop a table by using: Dim cmd As New OleDbCommand("DROP TABLE IF EXISTS books", myconnection) cmd.ExecuteNonQuery() but I get a syntax error: "Syntax error in DROP TABLE...
1
by: Dragan Matic | last post by:
if exists (select * from sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table . GO For instance, this is a valid script in Ms SQL, it will drop table...
6
by: Peter Nurse | last post by:
For reasons that are not relevant (though I explain them below *), I want, for all my users whatever privelige level, an SP which creates and inserts into a temporary table and then another SP...
3
by: db2admin | last post by:
Hello, I always assumed that dropping table will drop everything associated with it like indexes, references etc. I just noticed that after dropping table A and recreating it and then creating...
15
by: uwcssa | last post by:
I try to drop a table as: I got: During SQL processing it returned: SQL0478N The object type "TABLE" cannot be dropped because there is an object "sch.SQL070515104729271", of type "FUNCTION",...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.