SA0269 : Datatype identifier is not in the required case
Introduction
Section titled “Introduction”Ensure consistent casing for datatype keywords in T-SQL statements.
Description
Section titled “Description”Maintaining a uniform case for datatype identifiers is important for code readability and maintainability. The lack of consistency in keyword casing can lead to confusion, making it harder for developers to follow and debug the code. Although SQL Server is not case-sensitive by default, maintaining consistent casing is a best practice.
For example:
-- Example of inconsistent casing in datatype declarationsCREATE TABLE SampleTable ( ID INT, Name nvarchar(100), CreatedDate DATETIME);In this example, the datatypes INT , nvarchar , and DATETIME use inconsistent casing. Choosing a consistent style, such as all uppercase or lowercase, enhances code clarity.
-
Inconsistent casing can lead to misunderstandings among team members, affecting collaboration and communication.
-
It may increase the difficulty of code management and refactoring, as developers might need to spend extra time ensuring that casing is uniform.
How to fix
Section titled “How to fix”Ensure consistent casing for datatype identifiers in T-SQL queries to improve code readability and maintainability.
Follow these steps to address the issue:
1.Identify the datatype keywords in your T-SQL script that have inconsistent casing, such as INT , nvarchar , or DATETIME .
2.Determine the preferred case for datatype keywords according to your team’s style guide or the RequiredCase parameter configuration, such as all uppercase or lowercase.
3.Update the casing of all datatype keywords in your script to match the preferred style. This can be done manually or using a text editor’s case conversion functions.
4.Review and revise your T-SQL scripts to maintain consistent casing for all future database objects and queries.
For example:
-- Example of corrected query with consistent casingCREATE TABLE SampleTable ( ID int, Name nvarchar(100), CreatedDate datetime);The rule has a Batch scope and is applied only on the SQL script.
Parameters
Section titled “Parameters”| Name | Description | Default Value |
|---|---|---|
| RequiredCase | The parameter specifies the required case of the reserved keywords. | lowercase |
Remarks
Section titled “Remarks”The rule does not need Analysis Context or SQL Connection.
Effort To Fix
Section titled “Effort To Fix”2 minutes per issue.
Categories
Section titled “Categories”Naming Rules, Code Smells
Additional Information
Section titled “Additional Information”There is no additional info for this rule.
Example Test SQL
Section titled “Example Test SQL”CREATE TABLE Test.Greeting(GreetingId [INT] identity (1,1) PRIMARY KEY,Message [nvarchar](255) NOT NULL,)
CREATE TABLE Test.Greeting1(GreetingId int identity (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)
CREATE TABLE Test.Greeting2(GreetingId Int identity (1,1) PRIMARY KEY,Message nvarChar(255) NOT NULL,)
CREATE TABLE Test.Greeting1(GreetingId INT identity (1,1) PRIMARY KEY,Message NVARCHAR(255) NOT NULL,)Example Test SQL with Automatic Fix
Section titled “Example Test SQL with Automatic Fix”CREATE TABLE Test.Greeting(GreetingId [int] identity (1,1) PRIMARY KEY,Message [nvarchar](255) NOT NULL,)
CREATE TABLE Test.Greeting1(GreetingId int identity (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)
CREATE TABLE Test.Greeting2(GreetingId int identity (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)
CREATE TABLE Test.Greeting1(GreetingId int identity (1,1) PRIMARY KEY,Message nvarchar(255) NOT NULL,)Analysis Results
Section titled “Analysis Results”| Message | Line | Column | |
|---|---|---|---|
| 1 | SA0269 : Datatype identifier is not in the required case. | 3 | 11 |
| 2 | SA0269 : Datatype identifier is not in the required case. | 15 | 11 |
| 3 | SA0269 : Datatype identifier is not in the required case. | 16 | 8 |
| 4 | SA0269 : Datatype identifier is not in the required case. | 21 | 11 |
| 5 | SA0269 : Datatype identifier is not in the required case. | 22 | 8 |