|
|
(14 intermediate revisions by 6 users not shown) |
Line 1: |
Line 1: |
| == Database Development == | | {{Obsolete}} |
| The Dark Jedi Brotherhood's preferred database is [http://en.wikipedia.org/wiki/MySQL MySQL] despite its extensive [http://en.wikipedia.org/wiki/Microsoft_SQL_Server MS SQL Server] database structure. All new database developments should be done in MySQL as a full migration is in process. As such, the Table and Field standards apply to MySQL.
| | <center> |
| | {| class="fancy" style="margin:0 auto; width:75%;text-align:center;" |
| | |- |
| | |td colspan="3" class="head" style="background-color: #0000FF"| ''' Dark Brotherhood Coding Standards''' |
| | |- |
| | | class="sub-head" style="color: #DDD;" width="25%" | |
| | | class="sub-head" style="color: #DDD;" width="25%" | |
| | | class="sub-head" style="color: #DDD;" width="25%" | |
| | |- |
| | | [[ASP Coding Standards]] |
| | | [[CSS Coding Standards]] |
| | | [[Database Standards]] |
| | |- |
| | | [[HTML Coding Standards]] |
| | | [[JavaScript Coding Standards]] |
| | | [[PHP Coding Standards]] |
| | |- |
| | |} |
| | </center> |
|
| |
|
| == Table Standards == | | == Database Development == |
| | The Dark Jedi Brotherhood's preferred database is [http://en.wikipedia.org/wiki/MySQL MySQL] despite its extensive [http://en.wikipedia.org/wiki/Microsoft_SQL_Server MS SQL Server] database structure. All new database developments should be done in MySQL as a full migration is in process. As such, the Table and Field standards apply to MySQL. |
| | |
| | |
| | |
| | == Table Standards == |
| | |
| | === Naming Conventions === |
| | All table names must be in lower case; must have words within the table name separated with underscores; and should include a prefix to segregate specific functions within the [[DJB]]. For example: |
|
| |
|
| === Naming Conventions ===
| |
| All table names must be in lower case; must have words within the table name separated with underscores; and should include a prefix to segregate specific functions within the DJB. For example:
| |
|
| |
|
| * General DJB tables are prefixed with '''db_''' | | * General DJB tables are prefixed with '''db_''' |
| * Possession System tables are prefixed with '''dbpos_''' | | * Possession System tables are prefixed with '''dbpos_''' |
| * Competition specific tables are prefixed with '''dbcomp_''' | | * Competition specific tables are prefixed with '''dbcomp_''' |
| | The remainder of the table's name should indicate its contents in singular rather than plural. Association tables should be in ownership order. For example: |
|
| |
|
| The remainder of the table's name should indicate its contents in singular rather than plural. Association tables should be in ownership order. For example:
| |
|
| |
|
| * The user table for the DJB should be as follows: '''db_user''' | | * The user table for the DJB should be as follows: '''db_user''' |
Line 17: |
Line 41: |
| * The association table between users and items would be: '''dbpos_user_item''' | | * The association table between users and items would be: '''dbpos_user_item''' |
| * The association table between users and units would be: '''db_user_unit''' | | * The association table between users and units would be: '''db_user_unit''' |
| | Note: For a hint on ownership order, assume the user is the owner in all user association tables. |
| | |
| | |
| | |
| | === Indexes === |
| | All tables should be indexed appropriately. Indexes speed up data retrieval (sometimes by an alarming amount) at the expense of some performance when inserting, updating, or deleting records. Primary Keys, Unique Indexes, Indexes, and Full Text Indexes all have their place. See the [http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html MySQL Index Documentation] for more detailed information on index use. |
| | |
| | |
| | |
| | === Normalization === |
| | Table structures should be [http://en.wikipedia.org/wiki/Database_normalization normalized] as much as is reasonable. The primary benefits to normalization are: |
|
| |
|
| Note: For a hint on ownership order, assume the user is the owner in all user association tables.
| |
|
| |
|
| === Indexes ===
| | * The reduction of anomalies during database modification |
| All tables should be indexed appropriately. Indexes speed up data retrieval (sometimes by an alarming amount) at the expense of some performance when inserting, updating, or deleting records. Primary Keys, Unique Indexes, Indexes, and Full Text Indexes all have their place. See the [http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html MySQL Index Documentation] for more detailed information on index use.
| | * Minimize redesign effort when extending the database |
| | * Makes the data model more informative |
|
| |
|
| | == Field Standards == |
|
| |
|
| == Field Standards == | | === Naming Conventions === |
| | Fields must be in all lowercase and have words separated by underscores. Like table names, field names should intuitively explain what data they hold. Some tips to live by: |
|
| |
|
| === Naming Conventions ===
| |
| Fields must be in all lowercase and have words separated by underscores. Like table names, field names should intuitively explain what data they hold. Some tips to live by:
| |
|
| |
|
| * Base tables should not contain fields with its name prepended to them. For example: The '''db_user''' table should have fields named as follows: '''id, name, password''', not '''user_id, user_name, user_password'''. | | * Base tables should not contain fields with its name prepended to them. For example: The '''db_user''' table should have fields named as follows: '''id, name, password''', not '''user_id, user_name, user_password'''. |
| * Avoid keywords/reserved words as field names (like desc, asc, auto_increment, etc). | | * Avoid keywords/reserved words as field names (like desc, asc, auto_increment, etc.). |
| * Fields that reference other tables (typically in association tables) should include that table's name sans the prefix. For example: The '''dbpos_user_item''' table should contain the fields '''user_id, item_id'''. | | * Fields that reference other tables (typically in association tables) should include that table's name sans the prefix. For example: The '''dbpos_user_item''' table should contain the fields '''user_id, item_id'''. |
|
| |
|
| === Type Conventions === | | === Type Conventions === |
| MySQL offers a plethora of field types. Each type incurs affects the size of the table. Use what is appropriate, do not overdo it. | | MySQL offers a plethora of field types. Each type incurs affects the size of the table. Use what is appropriate, do not overdo it. |
|
| |
|
| Integers come with the most 'options'. Here are some tips: | | Integers come with the most 'options'. Here are some tips: |
| * Available integers in MySQL are: TINYINT (1 byte), SMALLINT (2 bytes), MEDIUMINT (3 bytes), INT (4 bytes), BIGINT (8 bytes). Each allow for different length numbers (obviously).
| |
| * Make integer field unsigned where possible...it doubles the number of positive values!
| |
| * Specifying an integer length in a field definition is useless. A mediumint always takes up 3 bytes regardless of how you specify the length.
| |
|
| |
|
| == Database Manipulation Language (DML) Standards ==
| |
|
| |
|
| ;RULE: Use all CAPITAL LETTERS for Common [http://en.wikipedia.org/wiki/SQL SQL] commands. Ex: “SELECT Member_ID FROM Members WHERE…”
| | * Available integers in MySQL are: TINYINT (1 byte), SMALLINT (2 bytes), MEDIUMINT (3 bytes), INT (4 bytes), BIGINT (8 bytes). Each allow for different length numbers (obviously). |
| | * Make integer field unsigned where possible...it doubles the number of positive values! |
| | * Specifying an integer length in a field definition is useless. A mediumint always takes up 3 bytes regardless of how you specify the length. |
|
| |
|
| :'''RATIONAL''': Allows for increased SQL statement readability
| | == Database Manipulation Language (DML) Standards == |
|
| |
|
| ;RULE: Avoid “[http://en.wikipedia.org/wiki/Select_(SQL) SELECT] *” statements. Use “SELECT field1, field2, field3…”
| | [http://en.wikipedia.org/wiki/Data_Manipulation_Language SQL] is a vital piece of interacting with any of the Brotherhood's databases. To ensure readability, the following standards should be adhered to where possible: |
|
| |
|
| :'''RATIONAL''': Allows for increased SQL statement readability and cuts down on transfer of unneeded data
| |
|
| |
|
| ;RULE: [http://en.wikipedia.org/wiki/Normalization Normalize] tables where possible
| |
|
| |
|
| :'''RATIONAL''': Increases the speed of data processing | | === Readability === |
| | Readability is key with SQL statements as they can be quite complex. To aid in the readability, using a standard format across all DJB scripts that interact with the database is a good plan. The Brotherhood has adopted the following standards: |
|
| |
|
| ;RULE: Index columns that will be updated regularly and have a variety of options. Ex: Index a Rank Column, but not a Gender Column.
| |
|
| |
|
| :'''RATIONAL''': Increases the speed of data processing and readability of table data
| | * Use all CAPITAL LETTERS for SQL keywords. e.g. SELECT, FROM, WHERE, ORDER BY, etc. |
| | * Use all lower letters for table and field names. |
|
| |
|
| ;RULE: Minimize the use of not equal operations, <> or !=. SQL Server has to scan a table or index to find all values to see if they are not equal to the value given in the expression. Try rephrasing the expression using ranges: WHERE KeyColumn < 'TestValue' AND KeyColumn > 'TestValue'
| | === Performance === |
| | Below are a list of some performance related tips with SQL: |
|
| |
|
| :'''RATIONAL''': Increases the speed of data processing
| |
|
| |
|
| [[Category: DJB Info]][[Category:Coding Standards]]
| | # '''Be specific!''' Avoid "SELECT *" statements where possible (and reasonable), using "SELECT field1, field2, field3..." instead. This increases statement readability at the same time as reducing the transfer of unneeded data. |
| | # '''Equal > Not Equal!''' Minimize the use of not equal operations, <> or !=. Queries that include those operations have to scan a table or index to find all values to see if they are not equal to the value given in the expression. Try rephrasing the expression using ranges: WHERE key_column < 'TestValue' AND key_column > 'TestValue' |
| | [[Category:Coding Standards]] |
|
You must unlearn what you have learned. This article contains obsolete data. It reflects a Dark Brotherhood policy, position, or object that has been removed or replaced. It is preserved here for historical purposes only and should not be used/referenced.
|
Database Development
The Dark Jedi Brotherhood's preferred database is MySQL despite its extensive MS SQL Server database structure. All new database developments should be done in MySQL as a full migration is in process. As such, the Table and Field standards apply to MySQL.
Table Standards
Naming Conventions
All table names must be in lower case; must have words within the table name separated with underscores; and should include a prefix to segregate specific functions within the DJB. For example:
- General DJB tables are prefixed with db_
- Possession System tables are prefixed with dbpos_
- Competition specific tables are prefixed with dbcomp_
The remainder of the table's name should indicate its contents in singular rather than plural. Association tables should be in ownership order. For example:
- The user table for the DJB should be as follows: db_user
- The possession system's item table for the DJB should be as follows: dbpos_item
- The association table between users and items would be: dbpos_user_item
- The association table between users and units would be: db_user_unit
Note: For a hint on ownership order, assume the user is the owner in all user association tables.
Indexes
All tables should be indexed appropriately. Indexes speed up data retrieval (sometimes by an alarming amount) at the expense of some performance when inserting, updating, or deleting records. Primary Keys, Unique Indexes, Indexes, and Full Text Indexes all have their place. See the MySQL Index Documentation for more detailed information on index use.
Normalization
Table structures should be normalized as much as is reasonable. The primary benefits to normalization are:
- The reduction of anomalies during database modification
- Minimize redesign effort when extending the database
- Makes the data model more informative
Field Standards
Naming Conventions
Fields must be in all lowercase and have words separated by underscores. Like table names, field names should intuitively explain what data they hold. Some tips to live by:
- Base tables should not contain fields with its name prepended to them. For example: The db_user table should have fields named as follows: id, name, password, not user_id, user_name, user_password.
- Avoid keywords/reserved words as field names (like desc, asc, auto_increment, etc.).
- Fields that reference other tables (typically in association tables) should include that table's name sans the prefix. For example: The dbpos_user_item table should contain the fields user_id, item_id.
Type Conventions
MySQL offers a plethora of field types. Each type incurs affects the size of the table. Use what is appropriate, do not overdo it.
Integers come with the most 'options'. Here are some tips:
- Available integers in MySQL are: TINYINT (1 byte), SMALLINT (2 bytes), MEDIUMINT (3 bytes), INT (4 bytes), BIGINT (8 bytes). Each allow for different length numbers (obviously).
- Make integer field unsigned where possible...it doubles the number of positive values!
- Specifying an integer length in a field definition is useless. A mediumint always takes up 3 bytes regardless of how you specify the length.
Database Manipulation Language (DML) Standards
SQL is a vital piece of interacting with any of the Brotherhood's databases. To ensure readability, the following standards should be adhered to where possible:
Readability
Readability is key with SQL statements as they can be quite complex. To aid in the readability, using a standard format across all DJB scripts that interact with the database is a good plan. The Brotherhood has adopted the following standards:
- Use all CAPITAL LETTERS for SQL keywords. e.g. SELECT, FROM, WHERE, ORDER BY, etc.
- Use all lower letters for table and field names.
Performance
Below are a list of some performance related tips with SQL:
- Be specific! Avoid "SELECT *" statements where possible (and reasonable), using "SELECT field1, field2, field3..." instead. This increases statement readability at the same time as reducing the transfer of unneeded data.
- Equal > Not Equal! Minimize the use of not equal operations, <> or !=. Queries that include those operations have to scan a table or index to find all values to see if they are not equal to the value given in the expression. Try rephrasing the expression using ranges: WHERE key_column < 'TestValue' AND key_column > 'TestValue'