設(shè)為首頁收藏本站Access中國

Office中國論壇/Access中國論壇

 找回密碼
 注冊

QQ登錄

只需一步,快速開始

返回列表 發(fā)新帖
查看: 2603|回復(fù): 6
打印 上一主題 下一主題

[查詢] 如何用SQL寫刪除整個表的記錄(保留原表的機(jī)構(gòu))?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2011-3-17 07:48:16 | 只看該作者 回帖獎勵 |倒序?yàn)g覽 |閱讀模式
本帖最后由 wangxy689 于 2011-3-17 07:49 編輯

我這樣寫為什么不對? DoCmd.RunSQL “delete * from 源數(shù)據(jù)表”  ,我發(fā)現(xiàn)能把新增的記錄刪除,以前的記錄卻刪除不了(也就是不能刪除真?zhèn)表的記錄),這是為什么?應(yīng)該怎么寫才對?
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2011-3-17 09:14:12 | 只看該作者
不可能啊。這里又沒有其它條件。。。傳上附件看看吧。
3#
發(fā)表于 2011-3-17 15:21:34 | 只看該作者
應(yīng)該不會的
4#
發(fā)表于 2011-3-17 15:21:51 | 只看該作者
數(shù)據(jù)源打開了嗎
5#
 樓主| 發(fā)表于 2011-3-21 20:45:14 | 只看該作者
打開了。就是新增加的數(shù)據(jù)能夠刪除,以前的數(shù)據(jù)不能刪除。
6#
 樓主| 發(fā)表于 2011-3-21 20:46:00 | 只看該作者
這是不是需要和FOXPRO 中的險select all 后再用刪除?
7#
發(fā)表于 2011-3-21 21:08:24 | 只看該作者
Deleting all data from an Access database

Sometimes it may be necessary to delete all the data in a database
while retaining the table structure. If done manually, this job can
quickly become tedious. If your database has many tables, the
following code will clear all the data in a hurry.

Dim ctr As Container, doc As Document, db As Database
Set db = CurrentDB()
Set ctr = db.Containers!Tables
For Each doc in ctr.Documents
   If Left$(doc.Name, 4) <> "MSys" Then 注釋:Table is not a system table
        db.Execute "Delete [" & doc.Name & "].*" & _
           "From [" & doc.Name & "];"
   End If
Next doc

You might not want to delete data from linked tables. This can be easily
accommodated by checking the Connect property for each TableDef document.
The modified code reads:

Dim ctr As Container, doc As Document, db As Database
Set db = CurrentDb()
Set ctr = db.Containers!tables
For Each doc In ctr.Documents
   If Left$(doc.Name, 4) <> "MSys" And _
     db.TableDefs(doc.Name).Connect = "" Then
   注釋:Table is not a system table or a linked table
     db.Execute "Delete [" & doc.Name & "].*" & _
       "From [" & doc.Name & "];"
   End If
Next doc

You must also have cascading updates/deletes enabled for this procedure
to clear the data from all tables. As an alternative, run the code
multiple times. On the first pass through the database, the tables on
one side of the relationship are cleared, allowing the remaining tables
to be cleared on the next pass.

This tip was contributed by Dr. Michael S. Stoner, Henri Kover, and Stephen Bond


您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號-1 )  

GMT+8, 2024-10-23 10:26 , Processed in 0.168724 second(s), 30 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表