Project Database Rules

Similar documents
Information Systems Engineering. SQL Structured Query Language DDL Data Definition (sub)language

Lab 4: Tables and Constraints

System Pages (Setup Admins Only)

BEGINNING T-SQL. Jen McCown MidnightSQL Consulting, LLC MinionWare, LLC

HOW TO CREATE AND MAINTAIN DATABASES AND TABLES. By S. Sabraz Nawaz Senior Lecturer in MIT FMC, SEUSL

Basis Data Terapan. Yoannita

Building Better. SQL Server Databases

SQL Server 2008 Tutorial 3: Database Creation

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

Introduction to SQL Server 2005/2008 and Transact SQL

CHAPTER4 CONSTRAINTS

Basic SQL. Basic SQL. Basic SQL

Introduction to ERwin

SQL Data Definition and Data Manipulation Languages (DDL and DML)

MySQL: an application

Building Better. SQL Server Databases

Creating the Data Layer

Chapter 4. Basic SQL. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

MTAT Introduction to Databases

Lab # 4. Data Definition Language (DDL)

ColdFusion Summit 2016

Basic SQL. Dr Fawaz Alarfaj. ACKNOWLEDGEMENT Slides are adopted from: Elmasri & Navathe, Fundamentals of Database Systems MySQL Documentation

SQL Functionality SQL. Creating Relation Schemas. Creating Relation Schemas

MySQL Creating a Database Lecture 3

Creating Tables, Defining Constraints. Rose-Hulman Institute of Technology Curt Clifton

Physical Design of Relational Databases

Full file at

Variables and Functions. ROBOTC Software

Data Definition Language (DDL)

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Islamic University of Gaza Faculty of Engineering Department of Computer Engineering Fall 2011 ECOM 4113: Database System Lab Eng.

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 2

SQL Data Definition Language

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

printf( Please enter another number: ); scanf( %d, &num2);

CST272 SQL Server, SQL and the SqlDataSource Page 1

Variables and numeric types

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

Getting started with Java

Database Programming with PL/SQL

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

Introduction to IBM DB2

Variables and Values

About System Setup Pages

Code Centric: T-SQL Programming with Stored Procedures and Triggers

Database Management (Functional) DELMIA Apriso 2018 Implementation Guide

Chapter 4. Basic SQL. SQL Data Definition and Data Types. Basic SQL. SQL language SQL. Terminology: CREATE statement

Visual C# Instructor s Manual Table of Contents

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

The type of all data used in a C (or C++) program must be specified

Exact Numeric Data Types

1 INTRODUCTION TO EASIK 2 TABLE OF CONTENTS

First of all, it is a variable, just like other variables you studied

DS Introduction to SQL Part 1 Single-Table Queries. By Michael Hahsler based on slides for CS145 Introduction to Databases (Stanford)

LBSC 690: Information Technology Lecture 05 Structured data and databases

Data types String data types Numeric data types Date, time, and timestamp data types XML data type Large object data types ROWID data type

CS634 Architecture of Database Systems Spring Elizabeth (Betty) O Neil University of Massachusetts at Boston

The type of all data used in a C++ program must be specified

SQL Data Definition: Table Creation

SQL: Data Definition Language

SQL Structured Query Language Introduction

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

Organization of Records in Blocks

Introduction to SQL Server. nikos bikakis

PART I SQLAlchemy Core

Ex: If you use a program to record sales, you will want to remember data:

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

618 Index. BIT data type, 108, 109 BIT_LENGTH, 595f BIT VARYING data type, 108 BLOB data type, 108 Boolean data type, 109

user specifies what is wanted, not how to find it

Db2 Alter Table Alter Column Set Data Type Char

The DBMS accepts requests for data from the application program and instructs the operating system to transfer the appropriate data.

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

Department of Computer Science University of Cyprus. EPL342 Databases. Lab 1. Introduction to SQL Server Panayiotis Andreou

A <column constraint> is a constraint that applies to a single column.

CS 231 Data Structures and Algorithms, Fall 2016

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

Lesson 2 Variables and I/O

Draft. Students Table. FName LName StudentID College Year. Justin Ennen Science Senior. Dan Bass Management Junior

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Data Definition Language with mysql. By Kautsar

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Get Table Schema In Sql Server 2008 To Add Column If Not Exists >>>CLICK HERE<<<

Programming in C++ 5. Integral data types

Data Types, Literals, Operators

1) Introduction to SQL

COMP 430 Intro. to Database Systems

Relational Model. CSE462 Database Concepts. Demian Lessa. Department of Computer Science and Engineering State University of New York, Buffalo

The Top 20 Design Tips

The C++ Language. Arizona State University 1

JDO XML MetaData Reference (v5.2)

Data and Tables. Bok, Jong Soon

Course Topics. Microsoft SQL Server. Dr. Shohreh Ajoudanian. 01 Installing MSSQL Server Data types

File Structures and Indexing

Chapter 1 Getting Started

Kaotii.

Transcription:

Company Header Project Database Rules Author: Contributors: Signed Off:

Table of Contents Introduction... 3 Database object naming conventions... 3 1. Tables... 3 2. Columns... 4 3. Indexes... 5 4. Constraints... 5 5. Views... 5 6. Rules for tables in [PRODUCT/PROJECT NAME]... 6 7. Stored Procedures... 6 7. User defined functions (UDFs)... 7 8. Summarising naming conventions... 7 9. Data types used in [PRODUCT/PROJECT NAME]... 7 References... 8

Introduction This document suggests a set of coding guidelines and database naming conventions and rules to be adhered to when writing SQL objects in. [TYPE YOUR INTRODUCTION TO THE DOCUMENT HERE ] Database object naming conventions 1. Tables [SPECIFY YOUR PROJECT SPECIFIC NAMING CONVENTIONS. HERE S A SAMPLE] Keep table names short and simple as possible. Do not use numbers or spaces in the names. For the [PRODUCT/PROJECT NAME] we will keep all table names singular. For example Customers should be Customer and so on. This is because we don t want to have any confusion as to where to use plural and where not to. Prefix : The table naming convention in [PRODUCT/PROJECT NAME] will be in this format : dbo.module ABBREVIATED NAME_TableName OR dbo.module ABBREVIATED NAME_TableNames_XREF Eg : o o dbo.pur_purchaseorder dbo.sal_invoiceheader Some of the common module abbreviated names could be : [LIST ALL THE MODULE ABBRIEVIATIONS FOR YOUR PROJECT] o PUR - For Purchase o SAL - For Sales o INV - For Inventory And so on. Try to keep the module abbreviation between 2 5 characters. If the table doesn t belong to a specific module, we could group them into Logical functionalities and have those functional names as a part of the table name. o dbo.core_xyzzz Notation : Use Pascal case. This reduces the need for underscores to visually separate words in names. o dbo.core_workflowprocessstage, which is more readable compared to core_workflowprocessstage If a table name could be long, try to abbreviate the words so that it s understandable by all developers. Over abbreviation is also disadvantageous as developers will not remember table names and have to keep referring the schema to identify tables.

o dbo.core_workflowprocessstage which is abbreviated for Workflow Process Stage This can be further abbreviated to CORE_WFProcessStage (CLEAR) But NOT CORE_WFPSt (UNCLEAR) Cross reference tables ( XREF tables ): For cross reference tables, which combines the Unique/Primary keys of 2 or more tables, we should suffix the table with _XREF. o dbo.core_supplierlocation_xref [SPECIFY THE SCHEMAS USED IN YOUR PROJECT] 2. Columns [SPECIFY ALL THE COLUMN RULES HERE. HERE S SOME EXAMPLES] Similar to table names, column names should be simple, short and understandable. Avoid abbreviations, acronymns, numbers, spaces and special characters. Column names should be in Pascal Case. No underscores or spaces between words. Primary key columns : Every table should have a primary key column. In [PRODUCT/PROJECT NAME] the primary key column name naming convention will either be : Table Name +ID For Location table. The primary column would be either LocationID. [Fix your own naming convention for the primary key column] [Fix your own datatype for the primary key column. Specify if it s a GUID, or an integer or a system generated value. Specify if it s an identity and so on.., here s a sample below ] The column will be an IDENTITY column. The column type will be INT, so that it can hold 2^32 rows. The reason for using identity columns is that SQL maintains the sequence of newly inserted rows automatically instead of us writing code to generate the next sequence manually. [SPECIFY IF THE PK IS CLUSTERED OR NON CLUSTERED BASED ON THE PERFORMANCE TESTS AND YOUR PROJECT USAGE ] Foreign key columns : FK column names should be the TableName +ID of the parent table where this column is the primary key. All tables will contain these columns : CreatedDate. This will be used for debugging and archiving purposes. [Specify any default columns that all your tables must have and what their datatypes are and their usage] Data Type Specific Naming : o Boolean fields should be given names like "IsHidden", "HasPermission" so that the meaning of the data in the field is not ambiguous. o If the field holds date and/or time information, the word "Date" or "Time" should appear somewhere in the field name.

o It is sometimes appropriate to add the unit of time to the field name also, especially if the field holds data like whole numbers ("3" or "20"). Those fields should be named like "WorkedHours" or "FreightMinutes". 3. Indexes Since indexes are always related to a table or view, it makes the most sense to use the name of the table or view, as well as the column(s) they index. The index naming convention in [PRODUCT/PROJECT NAME] will be : IDX_TableName_ColumnNames For composite indexes that span across multiple columns type the column names in Pascal Case. Underscores are therefore not required in the column names. If there are too many columns, try to abbreviate the columns so that the index name is not too long. Try to keep the index name short, maximum around 30-40 characters. [SPECIFY ALL THE RULES FOR CHOOSING CLUSTERED/NON CLUSTERED INDEXES. MENTION IF YOU ALLOW FILTERED INDEXES AND WHERE THEY SHOULD BE USED ] 4. Constraints Constraints are at the field/column level so the name of the field the constraint is on should be used in the name. The type of constraint (Check, Referential Integrity a.k.a Foreign Key, Primary Key, or Unique) should be noted also. Constraints are also unique to a particular table and field combination, so you should include the table name also to ensure unique constraint names across your set of database tables. Constraints naming convention in [PRODUCT/PROJECT NAME] will be : ConstraintTypePrefix_TableName_ColumnName For SAL_InvoiceHeader The primary key should be : PK_InvoiceHeader_InvoiceID The ConstraintType Prefixes as as follows : o PK - primary key ( PK_TableName_ColumnName ) o FK - foreign key ( FK_Table1Name_Table2Name_ColumnName ) o UN - unique key constraint ( UN_TableName_ColumnName ) o CHK - check constraint ( CHK_TableName_ColumnName ) o DF - default ( DF_TableName_ColumnName ) 5. Views Views follow similar rules that apply to naming tables Prefix : As a standard in [PRODUCT/PROJECT NAME] table naming convention we will prefix all tables with vw_ [SPECIFY YOUR NAMING CONVENTION HERE] The table naming convention will therefore be : dbo.vw_module ABBREVIATED NAME_ViewName

If the view combines just 1 or 2 tables then try to add the table names in the view name in Pascal notation. Eg : A view for PUR_Supplier and Location can be named as vw_pur_supplierlocation_xref If the view combines several tables then the name can be a understandable and developers should be able to easily understand what the view is meant for. vw_sal_monthlystockandbalanceinfo 6. Rules for tables in [PRODUCT/PROJECT NAME] Master tables : [Specify all the rules for the master tables, here some samples below ] All tables will have a primary key which is of int datatype and usually an identity column of seed = 1 and increment value = 1 [SPECIFY THE TYPE OF PK YOU WILL BE USING IN YOUR PROJECT] For all master records in [PRODUCT/PROJECT NAME], we will never physically delete a row from the table. We will always do a soft delete, i.e. there will be a bit column called isinactive which will be updated to 0 for an inactive record. [SPECIFY ANY COMMON RULES] There will be new columns for XYZ reasons: [SPECIFY ALL NEW/DEFAULT COLUMNS THAT GO INTO ALL MASTERS AND THEIR DATATYPES AND USAGE] [GIVE EXAMPLES HOW THESE ARE USED, WHEN THEY ARE POPULATED/CHANGED ETC] All tables : [SPECIFY COMMON RULES FOR ALL THE TABLES IN YOUR PROJECT ] Any column that can accept only a Boolean value will have to be a bit datatype. The column name should have is prefix. For example, isactive, isused etc... 7. Stored Procedures Unlike a lot of the other objects described above, stored procedures are not logically tied to any table or column. Typically though, stored procedures perform one of the CRUD (Create, Read, Update, and Delete) operations on a table, or another action of some kind. Since stored procedures always perform some type of operation, it makes sense to use a name that describes the operation they perform. Use a verb to describe the type of operation, followed by the table(s) the operations occur on. Prefix : As a standard [PRODUCT/PROJECT NAME] procedure naming convention we will prefix all procs with sproc_ The stored procedure naming convention will therefore be : [SPECIFY YOUR OWN NAMING CONVENTION HERE] dbo.sproc_module ABBREVIATED NAME_ProcedureName Do not prefix your stored procedures with something that will cause the system to think it is a system procedure. For example, in SQL Server, if you start a procedure with "sp_", "xp_" or "dt_" it will cause SQL Server to check the master database for this procedure first, causing a performance hit.

The module abbreviated name is similar to the one used above for tables. The procedure name should be understandable and describe the purpose of the procedure. sproc_core_executeworkflowstage 7. User defined functions (UDFs) UDFs follow similar naming convention to stored procedures. Prefix : The prefix for [PRODUCT/PROJECT NAME] functions will be UDF_ [SPECIFY YOUR OWN NAMING CONVENTION HERE] Therefore the naming convention for functions will be : dbo.udf_module ABBREVIATED NAME_FunctionName For functions that are not tied to a module but rather used as a utility, they can be just named as dbo.udf_taskname 8. Summarising naming conventions Limit the name to 30 characters (shorter is better) Use only letters or underscores (avoid numbers) Try to use underscore characters as little as possible. PascalCase notation achieves the same word separation without them. Use a letter as the first character of the name. (don't start names with underscores) Avoid abbreviations (can lead to misinterpretation of names) Avoid acronyms (some acronyms have more than one meaning eg. "ASP") Makes the name readable (they shouldn't sound funny when read aloud) Avoid using spaces in names even if the system allows it. 9. Data types used in [PRODUCT/PROJECT NAME] All primary data types are acceptable. There are rules while choosing a column datatype. These are the ones to be used in [PRODUCT/PROJECT NAME] : [SPECIFY ALL THE DATATYPES THAT YOU ARE GOING TO USE IN YOUR PROJECT. Here s a sample list] Data Type Storage Value Range Purpose Bit 1 bit Stores 0, 1 or null This is used for all Boolean columns. True is converted to 1 and False is converted to 0. Tinyint 1 byte 0 to 255 Use this if to store a small range of positive whole numbers Smallint 2 bytes -32768 to 32767 Stores whole numbers that are positive and negative Int 4 bytes -2^31 to 2^31-1 Stores whole numbers that are positive and negative Bigint 8 bytes -2^63 to 2^63-1 Stores very large positive/negative whole numbers. [PRODUCT/PROJECT NAME] will use this datatype for identity columns Float 4 or 8 bytes -2.23^308 to 2.23^308 Stores large, floating point numbers that exceed the capacity of a decimal data type. Use this datatype in [PRODUCT/PROJECT NAME] to store decimal values as well as columns to hold money values.

datetime 8 bytes Jan 1, 1753, Stores large date and time values through Dec 31 9999 varchar(n) 1-8000 bytes Maximum of 8000 characters ANSI data type of variable length. Use this for values that will not hold Non English characters nvarchar(n) 2-8000 bytes Maximum of 4000 characters Unicode data type of variable lengh. Use this data type for columns that could store other languages. But use this datatype cautiously.. as it occupies 2 byes per character nvarchar(max) Upto 2 GB Upto 536,870,912 Unicode variable width data type. Use this to store very characters large data. NOTE: to be used cautiously. This can now be used instead of text datatype for accepting XML data into stored procedures. SQL is doing away with text datatype in the future. image Upto 2 GB Stores variable-size binary data. To be used cautiously. XML Upto 2 GB XML documents of upto 2 GB Stores xml documents. References http://weblogs.asp.net/jamauss/articles/databasenamingconventions.aspx#tables http://www.sql-server-performance.com/articles/dev/sql_best_practices_p3.aspx http://databases.aspfaq.com/database/what-naming-convention-should-i-use-in-my-database.html http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1277452,00.html?track=nl-417