本文介绍了使用C#或SQL复制Access表结构和约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何使用.NET或SQL复制MS Access表的表结构及其所有约束,键等?我已经搜索并发现了一些复制列和类型的方法,但我需要带来约束,如主键。

Can someone tell me how to copy an MS Access table's table structure and all its constraints, keys, and etc. using .NET or SQL? I have searched and found a number of ways of copying the columns and types, but I need to bring across the constraints as well such as primary keys.

我有一个数据库与一堆表,我需要创建(仅结构)的新名称的副本。这需要在C#应用程序内执行,但我不在乎是否使用ADO或SQL,只要我能找到一种方法。

I have a database with a bunch of tables which I need to create copies of (structure only) with new names. This needs to be executed from within a C# application, but I do not care if it is done using ADO or SQL, just as long as I can find a way. Any tips would be greatly appreciated.

推荐答案

您可以导出到同一个数据库,这将创建一个包含所有索引的副本

You can "export" to the same database, which will create a copy with all indexes etc, but not relationships.

        // Start a new instance of Access for Automation
        oAccess = new Access.Application();

        // Open a database
        oAccess.OpenCurrentDatabase(@"z:\docs\test.accdb");
        oAccess.DoCmd.TransferDatabase(
            Access.AcDataTransferType.acExport,
            "Microsoft Access",
            @"z:\docs\test.accdb",
            Access.AcObjectType.acTable, 
            "table1",
            "newtable",true,false);

这篇关于使用C#或SQL复制Access表结构和约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:17