documentation/Reference/Code Analysis Rules/Redgate SQLFluff Rules Library.md
{% include enterprise.html %}
Flyway CLI ships with a packaged version of SQLFluff that includes additional rules written by Redgate.
If you are using the Redgate bundled version of SQLFluff then you will see something like this in the CLI output
SqlFluff version 3.4.2 (Redgate Bundle)
These rules are under development so expect the list to grow.
You should be aware that SQLFluff already comes with a variety of rules
redgate GroupAll Redgate-provided rules belong to the redgate group.
You can enable the redgate rule group and selectively disable specific rules you don’t want by using a configuration like the example below.
However, please keep in mind that new rules may be added to this group in future releases. As a result, including the entire group and upgrading to a newer version could unintentionally introduce changes that affect your existing setup.
[sqlfluff]
rules = redgate
exclude_rules = RG04,RG05
Also note that the configuration below will not work as expected. SQLFluff will exclude the entire redgate rule group, rather than keeping only the specific rules you want.
[sqlfluff]
rules = RG01,RG02
exclude_rules = redgate
{% include anchor.html link="RG01"%}
This will cause data loss unless handled carefully. This rule will identify instances of this so you can verify that it is desired behavior in this case.
all, redgateall{% include anchor.html link="RG02"%}
Please note that this can only be checked when a table is created, if a table is altered to increase the number then this can't be verified as it requires knowledge of the existing table structure in the database.
all, redgateallmax_columns: the maximum permissible columns in a table. Defaults to 20 columns
{% include anchor.html link="RG03"%}
This will cause data loss unless handled carefully. This rule will identify instances of this so you can verify that it is desired behavior in this case.
all, redgateall{% include anchor.html link="RG04"%}
The complete name of any schema-based database object consists of up to four identifiers: the server name, database name, schema name, and object name. Within a database, you only need the object name itself so long as it is in the same schema but by specifying the schema, the database engine needs less searching to identify it.
all, redgateallcreate table myschema.mytable(col int);
select * from myschema.mytable
create table myschema.mytable(col int);
select * from mydb.myschema.mytable
parts_allowed: The number of parts allowed in object naming, defaults to 1,2
{% include anchor.html link="RG05"%}
Creation of an index is likely to be a time and resource intensive activity so you may not want to do this when the database is already busy with the daily activity of running your business. This rule catches cases where index creation is included as part of other updates so you know to refactor the script to manage when the index creation occurs.
all, redgateall{% include anchor.html link="RG06"%}
A DELETE without a WHERE clause will delete every row in the table, you might be clearing things out for some reason but it could also be an accident waiting to happen.
all, redgateallDELETE FROM tools WHERE type = "ballpein ;
DELETE FROM tools;
{% include anchor.html link="RG07"%}
These could be a privilege escalation path that should be closely monitored and managed.
all, redgateall{% include anchor.html link="RG08"%}
These could be a privilege escalation path that should be closely monitored and managed.
all, redgatepostgres, snowflake{% include anchor.html link="RG09"%}
An UPDATE without a WHERE clause will modify every row in the table. It often leads to unintended data changes.
all, redgateallUPDATE customers SET status = 'inactive' WHERE status = 'pending';
UPDATE customers SET status = 'inactive';
{% include anchor.html link="RG10"%}
A data type modification in an existing table may lead to unintended changes or the loss of data.
all, redgateallALTER TABLE employees ADD hire_date DATE;
ALTER TABLE orders DROP COLUMN old_status;
ALTER TABLE customers MODIFY COLUMN last_name VARCHAR(50);
{% include anchor.html link="RG11"%}
A CREATE ROLE statement may require review to ensure proper access restrictions.
all, redgateall{% include anchor.html link="RG12"%}
Altering privileges for PUBLIC is discouraged, consider using explicit roles.
all, redgateall{% include anchor.html link="RG13"%}
TRUNCATE statements will remove all rows of data in the table
all, redgateall{% include anchor.html link="RG14"%}
This will cause data loss unless handled carefully. This rule will identify instances of this so you can verify that it is desired behavior in this case.
all, redgateall{% include anchor.html link="RG15"%}
Creating a table without a primary key constraint can lead to performance issues.
all, redgateall{% include anchor.html link="RG16"%}
This will cause data loss unless handled carefully. This rule will identify instances of this so you can verify that it is desired behavior in this case.
all, redgateMySQL{% include anchor.html link="RG17"%}
It is a good practice to include a description in the MS_Description extended property to document the purpose of a table.
all, redgateTSQL