Docs

MS SQL

Microsoft SQL Server is a relational database management system developed by Microsoft, designed for enterprise-level data storage, management, and analytics with robust security and scalability features. Read more here.

Example Usage

Make sure you have MS SQL installed and configured. Then, you can connect it straight into Better Auth.

auth.ts
import { betterAuth } from "better-auth";
import * as Tedious from 'tedious'
import * as Tarn from 'tarn'
 
const dialect = new MssqlDialect({
  tarn: {
    ...Tarn,
    options: {
      min: 0,
      max: 10,
    },
  },
  tedious: {
    ...Tedious,
    connectionFactory: () => new Tedious.Connection({
      authentication: {
        options: {
          password: 'password',
          userName: 'username',
        },
        type: 'default',
      },
      options: {
        database: 'some_db',
        port: 1433,
        trustServerCertificate: true,
      },
      server: 'localhost',
    }),
  },
})
 
export const auth = betterAuth({
  database: {
    dialect,
    type: "mssql"
  }
});
 

For more information, read Kysely's documentation to the MssqlDialect.

Schema generation & migration

The Better Auth CLI allows you to generate or migrate your database schema based on your Better Auth configuration and plugins.

MS SQL Schema Generation

MS SQL Schema Migration

✅ Supported✅ Supported
Schema Generation
npx @better-auth/cli@latest generate
Schema Migration
npx @better-auth/cli@latest migrate

Additional Information

MS SQL is supported under the hood via the Kysely adapter, any database supported by Kysely would also be supported. (Read more here)

If you're looking for performance improvements or tips, take a look at our guide to performance optimizations.

On this page