Poor Naming Standards Presented by: Niño R. Ricon Alain Anuevo MIT Presented to Dr. Armando and to the class of Database Design.

Slides:



Advertisements
Similar presentations
Sometimes you need to use data from more than one table. In example1, the report displays data from two separate tables. Employee IDs exist in the EMPLOYEES.
Advertisements

Session 2Introduction to Database Technology Data Types and Table Creation.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Maintenance Modifying the data –Add records –Delete records –Update records Modifying the design –Add fields into tables –Remove fields from a table –Change.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
FIS 431/631 Financial Information Systems: Analysis and Design ERD & Normalization Joe Callaghan Oakland University Department of Accounting & Finance.
Database – Part 2a Dr. V.T. Raja Oregon State University.
10/3/2000SIMS 257: Database Management -- Ray Larson Relational Algebra and Calculus University of California, Berkeley School of Information Management.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Entity Relationships. Relationships Relationships exist between entities The type of relationship is entirely dependent on the business rules The business.
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
N. J. Taylor Database Management Systems (DBMS) 1.
ASP.NET Programming with C# and SQL Server First Edition
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
DATA MODELING AND DATABASE DESIGN
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
Relational Database Concepts. Let’s start with a simple example of a database application Assume that you want to keep track of your clients’ names, addresses,
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
SQL Server 7.0 Maintaining Referential Integrity.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
WEEK 11 Database Design. TABLE INSTANCE CHARTS Create Tables.
Database Systems Microsoft Access Practical #1 Creating Tables Nos 215.
Copyright © 2005 Ed Lance Fundamentals of Relational Database Design By Ed Lance.
Databases MIS 21. Some database terminology  Database: integrated collection of data  Database Management System (DBMS): environment that provides mechanisms.
CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports.
IST 220 Introduction to Databases Course Wrap-up.
Database Design Sections 11 Database relationship, Integrity, keys, mapping conceptual model to logical/physical model Previous Section 12 – DDLesson11Fa12.ppt.
Constraints cis 407 Types of Constraints & Naming Key Constraints Unique Constraints Check Constraints Default Constraints Misc Rules and Defaults Triggers.
Module 4: Implementing Data Integrity
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Visual Programing SQL Overview Section 1.
Indexes and Views Unit 7.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Database Basics BCIS 3680 Enterprise Programming.
A table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows.
30-Nov-2006 Sakai Data Work Group 1 1 Sakai Assessing Interest in the Formation and Viability of a Data Work Group.
Session 1 Module 1: Introduction to Data Integrity
* Database is a group of related objects * Objects can be Tables, Forms, Queries or Reports * All data reside in Tables * A Row in a Table is a record.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
1 DBS201: More on SQL Lecture 2. 2 Agenda Select command review How to create a table How to insert data into a table.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
Copyright © 2016 Pearson Education, Inc. CHAPTER 7: ADVANCED SQL (PART I) Modern Database Management 12 th Edition Jeff Hoffer, Ramesh Venkataraman, Heikki.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
N5 Databases Notes Information Systems Design & Development: Structures and links.
Databases Chapter 9 Asfia Rahman.
Indexes By Adrienne Watt.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Basic Database Design COSC 2328 – Web Programming.
SQL LANGUAGE and Relational Data Model TUTORIAL
Poor Naming Standards.
Relational Database Model
CS122 Using Relational Databases and SQL
Spreadsheets, Modelling & Databases
Relational Database Design
CS3220 Web and Internet Programming SQL and MySQL
CS122 Using Relational Databases and SQL
Chapter 11 Managing Databases with SQL Server 2000
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
Displaying Data from Multiple Tables
CS122 Using Relational Databases and SQL
Presentation transcript:

Poor Naming Standards Presented by: Niño R. Ricon Alain Anuevo MIT Presented to Dr. Armando and to the class of Database Design

A. Database naming conventions The following types of database objects are discussed here: 1. Tables 2. Columns (incl. Primary, Foreign and Composite Keys) 3. Indexes 4. Constraints 5. Views 6. Stored Procedures 7. Triggers

ALL DATABASE OBJECTS Limit the name to 30 characters Use only letters or underscores Try to use underscore characters as little as possible Use a letter as the first character of the name Avoid abbreviations Avoid acronyms Makes the name readable Avoid using spaces in names even if the system allows it

1. TABLES Rule #1: Plural Names - This rule is applicable because tables are logical collections of one or more entities as records - just like collection classes are logical collections of one or more objects. Example: Customers instead of Customer UserRoles instead of UserRole

1. TABLES Rule #2: Prefixes- if used correctly, table prefixes can help you organize your tables into related groups or distinguish them from other unrelated tables ELSE they can cause you to have to type a lot of unnecessary characters. Example: for a healthcare application you might give your tables an "Hc" prefix so that all of the tables for that application would appear in alphabetized lists together.

1. TABLES Rule #3: Notation - For all parts of the table name, including prefixes, use Pascal Case. Using this notation will distinguish your table names from SQL keywords. Example: "SELECT CustomerId_Pk, CustomerName FROM MyAppGroupTable WHERE CustomerName = '%S'" shows the notation for the table name distinguishing it from the SQL keywords used in the query.

1. TABLES Rule #4: Special Characters The underscore character has a place in other object names but, not for tables Using Pascal Case for your table name allows for the upper-case letter to denote the first letter of a new word or name Do not use numbers in your table names Do not use spaces in your table names Example: PurchaseOrder instead of Purchase_Order SalesOrder instead of [sales order] SalesInventory instead of sales inventory 1

1. TABLES Rule #5: Abbreviations- avoid using abbreviations if possible. Example: Accounts instead of Accnts Hours instead of Hrs

1. TABLES Rule #6: Junction/Intersection Tables - its handle many to many relationships, should be named by concatenating the names of the tables that have a one to many relationship with the junction table. Example: You might have "Doctors" and "Patients" tables. Since doctors can have many patients and patients can have many doctors (specialists) you need a table to hold the data for those relationships in a junction table. This table should be named "DoctorsPatients". Since this convention can result in lengthy table names, abbreviations sometimes may be used at your discretion.

2. COLUMNS - Just like with naming tables, avoid using abbreviations, acronyms or special characters. All column names should use Pascal Case to distinguish them from SQL keywords. Rule #1: Identify Primary Key Fields- For fields that are the primary key for a table and uniquely identify each record in the table, the name should simply be “Id“ since, that's what it is - an identification field. Example: Customer table with primary key fields named ID

2. COLUMNS Rule #2: Foreign Key fields- it should have the exact same name as they do in the parent table where the field is the primary key - with one exception - the table name should be specified. Example: Customer table where primary key fields named ID and the foreign key is CustomerID from the Orders table.

2. COLUMNS Rule #3: Composite Keys- If you have tables with composite keys (more than one field makes up the unique value) then instead of just “Id“ you should use a descriptor before the “Id“ characters. Example: ID, ModuleID, CodeID

2. COLUMNS Rule #4: Prefixes- Do not prefix your fields with "fld_" or "Col_" as it should be obvious in SQL statements which items are columns (before or after the FROM clause). Including a two or three character data type prefix for the field is optional and not recommended, Example: "IntCustomerId" for a numeric type or "VcName" for a varchar type.

2. COLUMNS Rule #5: Data Type Specific Naming Example: Boolean data types = “IsDeleted” or ”HasPermission” Date/Time data types = “RuntimeHours” or “ScheduledMinutes”

3. INDEXES Rule #1: Naming Conventions Indexes Structure: {TableName}{ColumnsIndexed}{U/N}{C/N} where: U/N - Unique or Non-Unique C/N – Clustered or Non-Clustered Example: OrderDetailsOrderIdCustomerIdNN - indicates a non- unique, non-clustered index on the OrderId and CustomerId columns in the OrderDetails table.

3. INDEXES Rule #2: Prefixes and Suffixes Avoid "idx" or "IDX_" before your indexes. A suffix of "_idx" or "IDX" is not necessary.

4. CONSTRAINTS Rule #1: Naming Conventions Syntax: {constraint type}{table name}_{field name} Examples: 1. PkProducts_Id - primary key constraint on the Id field of the products table 2. FkOrders_ProductId - foreign key constraint on the productId field in the Orders table 3. CkCustomers_AccountRepId - check constraint on the accountRepId field in the Customers table

4. CONSTRAINTS Rule #2: Prefixes Primary Key: Pk Foreign Key: Fk Check: Ck Unique: Un

5. VIEWS Rule #1: Prefixes While it is pointless to prefix tables, it can be helpful for views. Prefixing your views with "Vw" or "View" is a helpful reminder that you're dealing with a view, and not a table. Whatever type of prefix you choose to apply, use at least 2 letters and not just "V" because a prefix should use more more than one letter or its meaning can be ambiguous.

5. VIEWS Rule #2: View Types For simple views that just join one or more tables with no selection criteria, combine the names of the tables joined. Example: Joining the "Customers" and "StatesAndProvinces" table to create a view of Customers and their respective geographical data should be given a name like "VwCustomersStatesAndProvinces".

6. STORED PROCEDURES Rule #1: Prefixes or Suffixes 1. Group by the type of CRUD operation Example: “CreateProductInfo” or “CreateOrder” 2. GRUD operation they perform Example: “ProductInfoCreate” or “OrdersCreate” 3. Performs an operation like validation, use the verb and noun combination Example: “ValidateLogin”

6. STORED PROCEDURES Rule #2: Grouping Prefixes If you have many stored procedures, you might want to consider using a grouping prefix that can be used to identify which parts of an application the stored procedure is used by. Example: "Prl" – Payroll related procedures "Hr" - Human Resources related procedures

6. STORED PROCEDURES Rule #3: Bad Prefixes Do not prefix your stored procedures with something that will cause the system to think it is a system procedure Example: "sp_", "xp_" or "dt_" – in SQL Server

7. TRIGGERS Rule #1: Prefixes/Suffixes To distinguish triggers from other database objects, it is helpful to add "Trg" as a prefix or suffix. Example: “ Trg_ProductsIns “, “ ProductsInsTrg “, “ Products_InsTrg” or InsProducts_Trg

7. TRIGGERS Rule #2: Multiple Operations If a trigger handles more than one operation (both INSERT and UPDATE for example) then include both operation abbreviations in your name. Example: "Products_InsUpdTrg" or "TrgProducts_UpdDel"

7. TRIGGERS Rule #3: Multiple Triggers Some systems allow multiple triggers per operation per table but make sure the names of these triggers are easy to distinguish. Example: "Users_Validate Address_InsTrg" "Users_MakeActionEntries_InsTrg".