Skip to content

SA0244 : Database object created,altered or dropped without specifiying schema name

Fully qualifying object names with their schema in CREATE , ALTER , and DROP statements helps avoid confusion with the user’s default schema, as well as errors and security issues.

In SQL Server, it is crucial to fully qualify object names in CREATE , ALTER , and DROP statements with their schema. Omitting the schema can result in SQL Server assuming the user’s default schema, which can lead to confusion, errors, or security issues.

For example:

-- Example of problematic query
CREATE TABLE TableName (ID INT);

The above statement might unintentionally create the table in the user’s default schema rather than the intended one, potentially leading to access issues or application errors.

  • Lack of clarity: Developers and administrators may not be able to easily discern the schema in which the object resides, leading to maintenance challenges.

  • Security risks: Objects may be unintentionally created in or altered within the wrong schema, making schema-based security measures ineffective.

Ensure all object names in CREATE , ALTER , and DROP statements are fully qualified with their schema to prevent errors and unintended behavior.

Follow these steps to address the issue:

1.Identify all CREATE , ALTER , and DROP statements in your T-SQL scripts that are missing schema qualification.

2.Modify each statement to include the schema name before the object name. For instance, change CREATE TABLE TableName to CREATE TABLE dbo.TableName if the table belongs to the dbo schema.

3.Test the updated scripts by executing them in a safe environment to ensure that objects are being created, altered, or dropped in the correct schema.

For example:

-- Example of corrected query
CREATE TABLE dbo.TableName (ID INT);

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

5 minutes per issue.

Design Rules, Code Smells

There is no additional info for this rule.

CREATE TABLE Test.Greeting
(
GreetingId INT IDENTITY (1,1) PRIMARY KEY,
Message nvarchar(255) NOT NULL,
)
CREATE TABLE Greeting
(
GreetingId INT IDENTITY (1,1) PRIMARY KEY,
Message nvarchar(255) NOT NULL,
)
DROP TABLE greeting;
DROP TABLE #tempTable1;
 MessageLineColumn
1SA0244 : The table is created without specifiying schema name.713
2SA0244 : The table is dropped without specifiying schema name.1211

Analysis Rules