How to copy a table schema and constraints to a table of different database?
SELECT INTO will create a new table with the same schema. So you could:
SELECT *
INTO newdb.dbo.newtable
FROM olddb.dbo.oldtable
To just copy the schema and not the data:
SELECT TOP 0 *
INTO newdb.dbo.newtable
FROM olddb.dbo.oldtable
This would not copy indexes or keys. To copy those, right click the table in SQL Sever Management Studio and choose 'Script table as'. That will give you a script you can run on the new database.
Copy Access table structure and constraints using C# or SQL
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);
Searching for a way to copy table data from one SQL Server database to another (concerning Identity and Foreign Keys)
Using the vendor's SQL Server database schema and loading the data yourself is typically the correct approach for migrating to SQL Server with packaged software. But there may be additional guidance available from the vendor.
Instead of trying to load the tables in an order that is compatible the foreign key constraints, which is not always even possible, disable all the foreign keys before loading the database and re-enable them after. See eg Temporarily disable all foreign key constraints
Related Topics
One-To-Many Query Selecting All Parents and Single Top Child for Each Parent
Oracle: How to Get Percent of Total by a Query
Group Data by the Change of Grouping Column Value in Order
Table in Excel from SQL Server Stored Procedure with Parameter Field in Workbook
How to Get Week Start and End Date String in Postgresql
How to List User Defined Types in a SQL Server Database
Postgresql: Foreign Key/On Delete Cascade
How to Join on a Stored Procedure
Using Window Functions in an Update Statement
How Does SQL Query Parameterisation Work
Maintaining Referential Integrity - Good or Bad
SQL Query to Return Only 1 Record Per Group Id
How to Sort the Result from String_Agg()
Selecting Rows Where Remainder (Modulo) Is 1 After Division by 2