The guide walks you through the following how-to topics:
1. Create a copy of the scripts folder on your local machine or check it out from source control.
2. Deploy the local scripts folder to the target database.
For more detailed instructions, see deploying a scripts folder with the dbForge Schema Compare command line.
The dbForge DevOps Automation for SQL Server product has a PowerShell cmdlet allowing you to compare and synchronize a required scripts folder with the target database.
To learn more about deploying a database using the cmdlet, please refer to our DevOps Automation for SQL Server documentation.
1. Create a batch file with the following content:
sqlcmd -S "server"-U "login"-P "password"-i "input_file"
PAUSE
where input_file is a path to the SQL file that will create the database.
2. Create a single SQL file that contains a script to add a new database. For example, the script can be as follows:
SET NOCOUNT ON
GO
PRINT 'Creating sales_demo1 database'
USE [master]
GO
DECLARE @db_name NVARCHAR(255);
SET @db_name = N'sales_demo';
IF EXISTS (SELECT 1 FROM sys.databases d WHERE d.name = @db_name)
BEGIN
EXEC (N'ALTER DATABASE '+@db_name+N' SET SINGLE_USER WITH ROLLBACK IMMEDIATE');
EXEC (N'DROP DATABASE '+@db_name);
END;
EXEC (N'CREATE DATABASE '+@db_name);
GO
USE sales_demo
GO
:On Error exit
:r "D:\sales_demo\Tables\dbo.Customers.sql"
:r "D:\sales_demo\Tables\dbo.OrderLines.sql"
:r "D:\sales_demo\Tables\dbo.Orders.sql"
:r "D:\sales_demo\Tables\dbo.Products.sql"
PRINT 'Creation is Completed'
GO
where :r is a SQLCMD command that parses additional Transact-SQL statements and SQLCMD commands from the file specified by <filename> into the statement cache.
3. Launch the command prompt and execute the batch file you’ve created.
To learn more about how to deploy a database from Source Control, see How to Build a Database from Source Control.
To learn about how to deploy a database from source control using dbForge Schema Compare, see Deploy a database from the source control.