Write coding standards for SQL #118

Closed
opened 2026-04-02 08:15:12 +00:00 by a24timsv · 2 comments
Collaborator

Parent issue: #8

Parent issue: #8
Collaborator

If coding conventions for a specific part is not documented here, please refer to /SQL style standard

Naming Conventions
General

  • All names should be unique
  • Names should not exeed 30 characters
  • Names should only contain letters,numbers and underscore.
  • Underscores are used insead of sapce where it would naturally accure in a name.Exampel(first_name not firstName).
  • All names should start with letters.
  • Avoid abrbreviations, if needed try to use commonly understood abbreviations

Tables

  • Use collective name or plural form as table name. Exampel(staff or employees not employe)
  • Never give table and columns the same name.
  • Use lower case letters. Example (sensors not Sensors)
  • Tables must contain at least one key.

Columns

  • Use singular name. Example(temp_value not temp_values)
  • Do not name a column with table name.
  • Avoid using suffixes as names, Insted use a specific name followed by a suffix. Eampel ( sensor_id not just id.)
  • Always use lowercase letters.

Table creation

  • use indentations to separeta CREATE TABLE, collumns and constraints to read easier. Example.
    CREATE TABLE staff (
    PRIMARY KEY (staff_num),
    staff_num INT(5) NOT NULL,
    first_name VARCHAR(100) NOT NULL,
    pens_in_drawer INT(2) NOT NULL,
    CONSTRAINT pens_in_drawer_range
    CHECK(pens_in_drawer BETWEEN 1 AND 99)
    );

Stored procedures

  • Name should be a verb, describing the acction.
  • Dont use prefixes as sp_xxx.

Universal suffixes

  • _id, a unique identifier such as a column that is a primary key.
  • _status, flag value or some other status of any type such as publication_status.
  • _total, the total or sum of a collection of values.
  • _num, denotes the field contains any kind of number.
  • _name, signifies a name such as first_name.
  • _seq, contains a contiguous sequence of values.
  • _date, denotes a column that contains the date of something.
  • _tally, a count.
  • _size, the size of something such as a file size or clothing.
  • _addr, an address for the record could be physical or intangible such as ip_addr.

Query syntax

  • Always use uppercase letters for keywords.Example(SELECT not Select).
  • Use full lenght keywords insted of avvreviations. Example(ABSOLUTE not ABS).
  • Use space after commas, before and after equalsigns.
  • Keywords should be on seperate lines and alligned to read easier.
    SELECT species_name, AVG(height) AS average_height
    FROM flora
    WHERE species_name = 'Banksia'
    OR species_name = 'Sheoak'
    OR species_name = 'Wattle'
    GROUP BY species_name, observation_date
If coding conventions for a specific part is not documented here, please refer to [/SQL style standard](https://www.sqlstyle.guide/) **Naming Conventions** **General** - All names should be unique - Names should not exeed 30 characters - Names should only contain letters,numbers and underscore. - Underscores are used insead of sapce where it would naturally accure in a name.Exampel(first_name not firstName). - All names should start with letters. - Avoid abrbreviations, if needed try to use commonly understood abbreviations **Tables** - Use collective name or plural form as table name. Exampel(staff or employees not employe) - Never give table and columns the same name. - Use lower case letters. Example (sensors not Sensors) - Tables must contain at least one key. **Columns** - Use singular name. Example(temp_value not temp_values) - Do not name a column with table name. - Avoid using suffixes as names, Insted use a specific name followed by a suffix. Eampel ( sensor_id not just id.) - Always use lowercase letters. **Table creation** - use indentations to separeta CREATE TABLE, collumns and constraints to read easier. Example. `CREATE TABLE staff (` ` PRIMARY KEY (staff_num),` ` staff_num INT(5) NOT NULL,` ` first_name VARCHAR(100) NOT NULL,` ` pens_in_drawer INT(2) NOT NULL,` ` CONSTRAINT pens_in_drawer_range` ` CHECK(pens_in_drawer BETWEEN 1 AND 99)` `);` **Stored procedures** - Name should be a verb, describing the acction. - Dont use prefixes as sp_xxx. **Universal suffixes** - _id, a unique identifier such as a column that is a primary key. - _status, flag value or some other status of any type such as publication_status. - _total, the total or sum of a collection of values. - _num, denotes the field contains any kind of number. - _name, signifies a name such as first_name. - _seq, contains a contiguous sequence of values. - _date, denotes a column that contains the date of something. - _tally, a count. - _size, the size of something such as a file size or clothing. - _addr, an address for the record could be physical or intangible such as ip_addr. **Query syntax** - Always use uppercase letters for keywords.Example(SELECT not Select). - Use full lenght keywords insted of avvreviations. Example(ABSOLUTE not ABS). - Use space after commas, before and after equalsigns. - Keywords should be on seperate lines and alligned to read easier. ` SELECT species_name, AVG(height) AS average_height` ` FROM flora ` ` WHERE species_name = 'Banksia'` ` OR species_name = 'Sheoak'` ` OR species_name = 'Wattle'` ` GROUP BY species_name, observation_date`
Collaborator

Reviewed and added to the Wiki.

Reviewed and added to the Wiki.
Sign in to join this conversation.
No milestone
No project
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K#118
No description provided.