Statement Compatibility

In the same batch, some statements are not compatible with others.

Statement Categories

A statement belonging to a category cannot be in the same batch as a statement of another category. Else, an error is raised.

The categories are:

Categories Statements
server parameters ALTER SERVER PARAMETER
backup, restore BACKUP DATABASE, RESTORE DATABASE
logins, users, roles CREATE LOGIN, ALTER LOGIN, DROP LOGIN, CREATE USER, ALTER USER, DROP USER, CREATE ROLE, ALTER ROLE, DROP ROLE
databases CREATE DATABASE, ALTER DATABASE, DROP DATABASE, ALTER AUTHORIZATION
tables CREATE TABLE, ALTER TABLE, DROP TABLE, CREATE INDEX, ALTER INDEX, DROP INDEX
queries INSERT, SELECT, UPDATE, DELETE, TRUNCATE TABLE, BULK INSERT, BULK EXPORT, SHRINK TABLE

Statements of different categories must be sent to the server in separate batches.

When using the RSQL Client rcli, it is possible to write a script containing several batches.

Examples

This script contains three batches, separated by the GO command.

IF OBJECT_ID ('mytable', 'U') IS NOT NULL
    DROP TABLE mytable;

CREATE TABLE mytable (a INT IDENTITY NOT NULL, b VARCHAR(50) NULL);
GO

INSERT mytable VALUES ('Row #1'), ('Row #2');
SELECT * FROM mytable;
GO

DROP TABLE mytable;