How to clone a SQL Server database using a SQL query - sql-server

Similar to what exists in Postgres:
CREATE DATABASE clonedDB WITH TEMPLATE OriginalDB
I am looking for same in SQL Server.
For cloning database on the same sql server.

SQL Server has a "template database" that all new databases are a copy of, Model.
The model database is used as the template for all databases created
on an instance of SQL Server.
Model Database
If you want to copy some other database, use backup/restore or the SSMS Copy Database Wizard.

Related

How to copy table from SQL Linked Server to SQL Server and maintain key constraints?

I have an SQL Server installed on a local Windows 10 machine - I'm using Microsoft SQL Server Management Studio to interact with it.
I also have a DB2 database hosted on an IBM i machine and I've created a Linked Server in SQL Server Management Studio to represent it. I can connect to the Linked Server and can query/pull data from it successfully.
I'm trying to copy particular tables from the Linked Server and insert them into a Database/Schema in the SQL Server - I can do this successfully but unfortunately, it appears that in the process of copying the table over, none of the constraints (particularly in my case, the key constraints) are maintained.
Is there a simple way to copy over tables from a Linked Server to SQL Server (in SQL Server Management Studio) while maintaining key constraints?
The following query is an example of what I'm using to copy the tables over (one-by-one):
SELECT *
INTO SQLSCHEMA.SQLTABLE
FROM LINKSERVER.LINKDATABASE.LINKSCHEMA.LINKTABLE
The easiest way is to use proper tool for it like SSMA:
Microsoft SQL Server Migration Assistant (SSMA) is a tool designed to automate database migration to SQL Server from Microsoft Access, DB2, MySQL, Oracle, and SAP ASE.
Migrating DB2 Databases to SQL Server (DB2ToSQL)
SQL Server Migration Assistant (SSMA) for DB2 is a comprehensive environment that helps you quickly migrate DB2 databases to SQL Server or Azure SQL DB. By using SSMA for DB2, you can review database objects and data, assess databases for migration, migrate database objects to SQL Server or Azure SQL DB, and then migrate data to SQL Server or Azure SQL DB. Note that you cannot migrate SYS and SYSTEM DB2 schemas.

BulkCopy Firebird database to Azure SQL Server databasae

I am looking to copy data from a Firebird database into a SQL Azure database. I have a small program that SQL bulk copies from one SQL datatable to another.
Is possible to do something similar with the Firebird and the SQL Server without exporting data to CSV first?

How can I move data from SQL Server to Oracle?

I have created my database and tables in a SQL Server Express database. And now I migrated the database tables to Oracle with Entity Framework. But my tables are empty in Oracle. How can I move my data to Oracle?
Use SSIS interface from MS-SQL (Sql Server Integration Service).
I have used to move content from MSSQL to MySQL you should use the correct odbc driver.
For express edition, You can use Linked Servers to establish connection between SQL Server and Oracle. In this way, you should insert the records by creating queries for per table.
https://learn.microsoft.com/en-us/sql/relational-databases/linked-servers/linked-servers-database-engine

Migrate SQL Server Express to existing Oracle database with migrations

I have a project with a SQL Server Express database and Entity Framework migrations. But I need to migrate my SQL Server Express database to Oracle. But Oracle database has existing tables. How can I migrate to Oracle?
If I set Oracle connection strings and run a command update-database in package manager console, will existing database tables be deleted? Or what is the best way?
Funny question does the Oracle db tables have data stored?

I can't use a database in SQL Azure

I am trying to use a Database in SQL Azure. I have installed SQL Server 2008. I can Login SQL Azure and can use master Database. But I can't use other Database and I can't see any things in my object explorer. It shows this error:
"USE statement is not supported to switch between databases. Use a new connection to connect to a different Database."
How can I use another database?
You cannot link to another database server from SQL Azure, whether that other database is SQL Server or SQL Azure.
I found the Solution for this problem . I install SQL Server 2008 R2. then every thing is ok...
You can first create only the database before running the whole script to create schemas & Tables.
Then manually change the database to the new DB that was created.
Run the rest of the script. Do not run Use <databasename>

Resources