new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

mssql/insert

8 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

MSSQL insert basic syntax

Use db.insert(table).values({columns}) to insert rows into a table. All values are automatically parameterized to prevent SQL injection.

Infer insert type from table schema

Use typeof table.$inferInsert to get the TypeScript type for inserting into a specific table. This type includes all columns that can be inserted.

MSSQL insert with OUTPUT clause

Use .output() method to return inserted rows using MSSQL's OUTPUT clause. Call .output({columns}) to return specific columns, or .output() without arguments to return all inserted columns as typeof table.$inferSelect[].

MSSQL insert multiple rows

Pass an array of objects to .values() to insert multiple rows in a single statement: db.insert(table).values([{row1}, {row2}]).

MSSQL upsert limitations

MSSQL does not support PostgreSQL-style ON CONFLICT or MySQL-style ON DUPLICATE KEY UPDATE clauses. For upsert workflows, use a transaction with explicit select/update/insert logic or execute a dialect-specific MERGE statement with the sql operator.

MSSQL insert into select not supported

The insert into ... select pattern is currently not supported in Drizzle ORM for MSSQL.

MSSQL insert query example with output

Example showing how to insert multiple rows and return specific columns: const result = await db.insert(usersTable).output({ id: usersTable.id }).values([{ name: 'John' }, { name: 'John1' }]); // result type is { id: number }[]

MSSQL insert all columns output example

Example showing how to insert a row and return all columns: const result = await db.insert(usersTable).output().values({ name: 'John' }); // result type is typeof usersTable.$inferSelect[]

Give your agent this brain