Best Practices in database Designing
Proper table name, Normalization, Primary key , foreign key etc.
Best Practices in SQL writing
Reserve word is capital , Joins, Where clause, comment etc.
Best Practices in Index creation
Index on field, index on field combination etc.
Best Practices in Maintenance
Full backup, partial backup, Reindex etc.
What it means ?
People just choose the data type not according to business need else they choose according to there own impression.
So generally they choose large size for data type field and sometime it works some time not.
Why we choose appropriate data type ?
Size on the Hard Disk
Searching slow in large DB
Backup issue (slow)
What it means ?
We forgot to put constraints some time NOT NULL is one of them.
If you visit same example if you will find at many places where value.
is required according to business but still we allow them null and make the field Null able
Why we put constraints ?
We thought we will handle all the things in programming but sometime due to some poor programming logic or some misunderstanding we missed such validation and which cause anomalies and data integrity issue.
What it means ?
People are in hurry so they do not write proper joins. You can use Inner Join, Left Outer Join, Right Outer Join, Cross Join etc.
It depends on your business condition what to use when. Try to Avoid IN & NOT IN.
Why should we avoid IN ,NOT IN?
.Performance issue (** Sometime it may not work)
How to avoid IN ?
How to avoid NOT IN ?
What it means ?
We generally right the query with “*” and sometime we also forgot to write where clause. But as a best practices we should use proper column name if the we have to choose few columns not all. filter data as much as possible don’t think we will do programming and filter there.
Why we should use column name, and where clause?
less data then on the network it travel fast across network.
Programs like ADO.NET /EF keep the data in Memory so if the selection is * with out Where clause it will be in memory. And the application will be slow down later on.
What it means ?
Most of the time people think if a SQL statement execution is slow they not think to much to revise it and try to rewrite it they just apply the Index and there goal is achieved.
How & When to Select Index and which index is most suitable ?
When you tried your level best in rewriting and there is no other way to fetch fast result then you can apply index at the end.
You can create index generally on the fields which are used in WHERE clause, Join.