Friday, February 10, 2012

Basic things to learn for Relational DB Table Creation



  •  Table name should be relevant. Not necessary to add project name with table name
  • First column should be integer, not null, primary key and auto increment. Have (TABLENAME_ID). It will help for the foreign key reference. Rather just saying "ID".
  • When you have NOT NULL try to have Default Value (ex : double(10,2) DEFAULT 0.00)
  • If the column is foreign key you should have a constraint and the table should be created as InnoDB Engine
  • Try to have indexing if you know the table size is going to be huge
  • Try to have constraint in db level based on the project requirement to avoid unwanted corrupted data (unique key to avoid duplicate, composite key....)
  • Have last_modified and created_on with timestamp data type column (NOT NULL) always for auditing and support. Mysql will automatically make last_modified column with Default 'Current_TimeStamp' and Extra 'on update CURRENT_TIMESTAMP'
  • Never have definer on table, view, stored procs, trigger creation. When other user take dump and restore they may face issues.
  • Foreign key (FK) name cannot have the same name in a single database. 

No comments :

// Below script tag for SyntaxHighLighter