for each tdf in backup_db.tabledefs
if (tdf.attributes and dbsystemobject)=0 then
//条件成立,说明该表是用户定义的表,可以链接,否则跳过
end if
next
③ 使用create_table()对每个表创建与之对应的备份表,取名可遵循如下原则, 若原表叫table_name, 则备份表叫b_table_name。
④ 将table_name表中的所有记录复制到b_table_name中。
⑤从备份库删除对sql数据表的链接。
3、程序原码
采用微软dao (data access object) 数据模型, 打开access 本地数据库, 并连接一个外部odbc数据表, 拷贝该表结构完成, 有以下过程块copystru :
private sub copystru ()
set dbstemp = wrkjet. opendatabase (tagfilname)// 链接表的过程
for i = 0 to tabn - 1
set tdflinked = dbstemp. createtabledef (“linktab”)
tdflinked. connect = “odbc; database = xgsbgsys ; uid =
sa ; pwd = ; dsn = xgsdb ;”
tdflinked. sourcetablename = tabname (i)
dbstemp. tabledefs. append tdflinked
set temp tab = dbstemp. createtabledef ()
temp tab. name = tabname (i)
//创建新表的过程
for each fld in tdflinked. fields
set newfil = temp tab. createfield (fld. name , fld. type ,fld. size)
newfil. ordinalposition = fld. ordinalposition
newfil. required = fld. required
temp tab. fields. append newfil
next
//创建索引
for each idx in tdflinked. indexes
set newidx = temp tab. createindex ()
with newidx
name = tabname (i) & ” x”
fields = idx. fields
unique = idx. unique
primary = idx. primary
end with
temp tab. indexes. append newidx
next
dbstemp. tabledefs. append temp tab
set temp tab = nothing
dbstemp. tabledefs. delete ”linktab”
next i
dbstemp. close
set dbstemp = nothing
wrkjet. close
set wrkjet = nothing
end sub
end sub
中国最大的web开发资源网站及技术社区,
新闻热点
疑难解答