Want to deploy your JVM, Node.js and Go apps effortlessly to AWS? Try our service Boxfuse

SQL Server

Supported Versions

Driver

URL format jdbc:sqlserver://host:port;databaseName=database
Ships with Flyway Command-line Yes
Maven Central coordinates com.microsoft.sqlserver:mssql-jdbc:7.0.0.jre8
Supported versions 4.0 and later
Default Java class com.microsoft.sqlserver.jdbc.SQLServerDriver

SQL Script Syntax

Compatibility

  • DDL exported by SQL Server can be used unchanged in a Flyway migration.
  • Any SQL Server sql script executed by Flyway, can be executed by Sqlcmd, SQL Server Management Studio and other SQL Server-compatible tools (after the placeholders have been replaced).

Example

/* Single line comment */
CREATE TABLE Customers (
CustomerId smallint identity(1,1),
Name nvarchar(255),
Priority tinyint
)
CREATE TABLE Sales (
TransactionId smallint identity(1,1),
CustomerId smallint,
[Net Amount] int,
Completed bit
)
GO

/*
Multi-line
comment
*/
-- TSQL
CREATE TRIGGER dbo.Update_Customer_Priority
 ON dbo.Sales
AFTER INSERT, UPDATE, DELETE
AS
WITH CTE AS (
 select CustomerId from inserted
 union
 select CustomerId from deleted
)
UPDATE Customers
SET
 Priority =
   case
     when t.Total < 10000 then 3
     when t.Total between 10000 and 50000 then 2
     when t.Total > 50000 then 1
     when t.Total IS NULL then NULL
   end
FROM Customers c
INNER JOIN CTE ON CTE.CustomerId = c.CustomerId
LEFT JOIN (
 select
   Sales.CustomerId,
   SUM([Net Amount]) Total
 from Sales
 inner join CTE on CTE.CustomerId = Sales.CustomerId
 where
   Completed = 1
 group by Sales.CustomerId
) t ON t.CustomerId = c.CustomerId
GO

-- Placeholder
INSERT INTO ${tableName} (name) VALUES ('Mr. T');

Limitations

DB2