sammy sammy - 1 year ago 135
C# Question

Copy Access table structure and constraints using C# or SQL

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.

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.

Answer Source

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
            "Microsoft Access",
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download