SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
 
   
1  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
INDEX 
Guidelines for SQL SERVER 
1  Important Guidelines for SQL Server………………………….. 2 
 
 
 
 
 
 
 
Notice: 
All rights reserved worldwide. No part of this book may be reproduced or copied or 
translated in any form by any electronic or mechanical means (including photocopying, 
recording, or information storage and retrieval) without permission in writing from the 
publisher, except for reading and browsing via the World Wide Web. Users are not permitted 
to mount this file on any network servers. 
 
For more information send email to: pinal@sqlauthority.com 
 
 
 
 
   
2  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
Important Guidelines for SQL SERVER 
• Use "Pascal" notation for SQL server Objects Like Tables, Views, Stored Procedures. 
Also tables and views should have ending "s". 
Example:  
UserDetails  
Emails 
 
• If you have big subset of table group than it makes sense to give prefix for this table 
group. Prefix should be separated by _.  
Example: 
Page_ UserDetails 
Page_ Emails 
 
• Use following naming convention for Stored Procedure. sp<Application 
Name>_[<group name >_]<action type><table name or logical instance> Where action 
is: Get, Delete, Update, Write, Archive, Insert... i.e. verb  
Example:  
spApplicationName_GetUserDetails  
spApplicationName_UpdateEmails 
 
• Use following Naming pattern for triggers: TR_<TableName>_<action><description>  
Example:  
TR_Emails_LogEmailChanges  
TR_UserDetails_UpdateUserName 
 
• Indexes : IX_<tablename>_<columns separated by_>  
Example:  
IX_UserDetails_UserID 
 
• Primary Key : PK_<tablename>  
Example:  
PK_UserDetails  
PK_ Emails 
 
 
 
   
3  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• Foreign Key : FK_<tablename_1>_<tablename_2>  
Example:  
FK_UserDetails_Emails 
 
• Default: DF_<table name>_<column name>  
Example:  
DF_ UserDetails _UserName 
 
• Normalize Database structure based on 3rd
 Normalization Form. Normalization is the 
process of designing a data model to efficiently store data in a database. (Read More 
Here) 
 
• Avoid use of SELECT * in SQL queries. Instead practice writing required column names 
after SELECT statement. 
Example: 
SELECT   Username, Password 
FROM    UserDetails 
 
• Avoid using temporary tables and derived tables as it uses more disks I/O. Instead use 
CTE (Common Table Expression); its scope is limited to the next statement in SQL query. 
(Read More Here) 
 
• Use SET NOCOUNT ON at the beginning of SQL Batches, Stored Procedures and Triggers. 
This improves the performance of Stored Procedure. (Read More Here) 
 
• Properly format SQL queries using indents. 
Example: Wrong Format  
SELECT Username, Password FROM UserDetails ud INNER JOIN Employee e ON
e.EmpID = ud.UserID 
 
Example: Correct Format 
SELECT   Username, Password  
FROM    UserDetails ud  
INNER JOIN  Employee e ON e.EmpID = ud.UserID 
 
 
 
   
4  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• Practice writing Upper Case for all SQL keywords. 
Example: 
SELECT, UPDATE, INSERT, WHERE, INNER JOIN, AND, OR, LIKE. 
 
• There must be PRIMARY KEY in all the tables of database with column name ID. It is 
common practice to use Primary Key as IDENTITY column. 
 
• If “One Table” references “Another Table” than the column name used in reference 
should use the following rule : 
Column of Another Table : <OneTableName> ID 
Example: 
If User table references Employee table than the column name used in reference should 
be UserID where User is table name and ID primary column of User table and UserID is 
reference column of Employee table. 
 
• Columns with Default value constraint should not allow NULLs. 
 
• Practice using PRIMARY key in WHERE condition of UPDATE or DELETE statements as 
this will avoid error possibilities. 
 
• Always create stored procedure in same database where its relevant table exists 
otherwise it will reduce network performance. 
 
• Avoid server‐side Cursors as much as possible, instead use SELECT statement. If you 
need to use cursor then replace it with WHILE loop (or read next suggestion). 
 
• Instead of using LOOP to insert data from Table B to Table A, try to use SELECT 
statement with INSERT statement. (Read More Here) 
 
INSERT INTO Table A (column1, column2) 
SELECT column1, column2 
FROM Table B 
WHERE …. 
 
 
   
5  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• Avoid using spaces within the name of database objects; this may create issues with 
front‐end data access tools and applications. If you need spaces in your database object 
name then will accessing it surround the database object name with square brackets. 
Example: 
[Order Details] 
 
• Do not use reserved words for naming database objects, as that can lead to some 
unpredictable situations. (Read More Here) 
 
• Practice writing comments in stored procedures, triggers and SQL batches, whenever 
something is not very obvious, as it won’t impact the performance. 
 
• Do not use wild card characters at the beginning of word while search using LIKE 
keyword as it results in Index scan. 
 
• Indent code for better readability. (Example) 
 
• While using JOINs in your SQL query always prefix column name with the table name. 
(Example). If additionally require then prefix Table name with ServerName, 
DatabaseName, DatabaseOwner. (Example) 
 
• Default constraint must be defined at the column level. All other constraints must be 
defined at the table level. (Read More Here) 
 
• Avoid using rules of database objects instead use constraints. 
 
• Do not use the RECOMPILE option for Stored Procedure as it reduces the performance. 
 
• Always put the DECLARE statements at the starting of the code in the stored procedure. 
This will make the query optimizer to reuse query plans. (Example) 
 
• Put the SET statements in beginning (after DECLARE) before executing code in the 
stored procedure. (Example) 
 
• Use BEGIN…END blocks only when multiple statements are present within a conditional 
code segment. (Read More Here) 
 
   
6  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• To express apostrophe within a string, nest single quotes (two single quotes). 
Example: 
SET @sExample = 'SQL''s Authority' 
 
• When working with branch conditions or complicated expressions, use parenthesis to 
increase readability. 
Example: 
IF ((SELECT 1 
  FROM TableName  
WHERE 1=2) ISNULL) 
 
• To mark single line as comment use (‐‐) before statement. To mark section of code as 
comment use (/*...*/). 
 
• Avoid the use of cross joins if possible. (Read More Here) 
 
• If there is no need of resultset then use syntax that doesn’t return a resultset. 
IF EXISTS (SELECT  1  
       FROM  UserDetails  
       WHERE  UserID = 50)   
 
Rather than, 
IF EXISTS (SELECT  COUNT (UserID)  
         FROM  UserDetails  
       WHERE  UserID = 50) 
 
• Use graphical execution plan in Query Analyzer or SHOWPLAN_TEXT or 
SHOWPLAN_ALL commands to analyze SQL queries. Your queries should do an “Index 
Seek” instead of an “Index Scan” or a “Table Scan”. (Read More Here) 
 
• Do not prefix stored procedure names with “SP_”, as “SP_” is reserved for system 
stored procedures. 
Example: 
 SP<App Name>_ [<Group Name >_] <Action><table/logical instance> 
 
   
7  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• Incorporate your frequently required, complicated joins and calculations into a view so 
that you don’t have to repeat those joins/calculations in all your queries. Instead, just 
select from the view. (Read More Here) 
 
• Do not query / manipulate the data directly in your front end application, instead create 
stored procedures, and let your applications to access stored procedure. 
 
• Avoid using ntext, text, and image data types in new development work. Use nvarchar 
(max), varchar (max), and varbinary (max) instead. 
 
• Do not store binary or image files (Binary Large Objects or BLOBs) inside the database. 
Instead, store the path to the binary or image file in the database and use that as a 
pointer to the actual file stored on a server. 
 
• Use the CHAR datatype for a non‐nullable column, as it will be the fixed length column, 
NULL value will also block the defined bytes. 
 
• Avoid using dynamic SQL statements. Dynamic SQL tends to be slower than static SQL, 
as SQL Server generate execution plan every time at runtime. 
 
• Minimize the use of Nulls. Because they incur more complexity in queries and updates. 
ISNULL and COALESCE functions are helpful in dealing with NULL values 
 
• Use Unicode datatypes, like NCHAR, NVARCHAR or NTEXT if it needed, as they use 
twice as much space as non‐Unicode datatypes. 
 
• Always use column list in INSERT statements of SQL queries. This will avoid problem 
when table structure changes. 
 
• Perform all referential integrity checks and data validations using constraints instead of 
triggers, as they are faster. Limit the use of triggers only for auditing, custom tasks, and 
validations that cannot be performed using constraints. 
 
• Always access tables in the same order in all stored procedure and triggers consistently. 
This will avoid deadlocks. (Read More Here) 
 
 
   
8  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• Do not call functions repeatedly in stored procedures, triggers, functions and batches, 
instead call the function once and store the result in a variable, for later use. 
 
• With Begin and End Transaction always use global variable @@ERROR, immediately 
after data manipulation statements (INSERT/UPDATE/DELETE), so that if there is an 
Error the transaction can be rollback. 
 
• Excessive usage of GOTO can lead to hard‐to‐read and understand code. 
 
• Do not use column numbers in the ORDER BY clause; it will reduce the readability of SQL 
query. 
Example: Wrong Statement 
SELECT   UserID, UserName, Password 
FROM    UserDetails 
ORDER BY  2 
 
Example: Correct Statement 
SELECT   UserID, UserName, Password 
FROM    UserDetails 
ORDER BY  UserName 
 
• To avoid trips from application to SQL Server, we should retrive multiple resultset from 
single Stored Procedure instead of using output param. 
 
• The RETURN statement is meant for returning the execution status only, but not data. If 
you need to return data, use OUTPUT parameters. 
 
• If stored procedure always returns single row resultset, then consider returning the 
resultset using OUTPUT parameters instead of SELECT statement, as ADO handles 
OUTPUT parameters faster than resultsets returned by SELECT statements. 
 
• Effective indexes are one of the best ways to improve performance in a database 
application. 
 
• BULK  INSERT  command  helps  to  import  a  data  file  into  a  database  table  or  view  in  
a  user‐specified  format. 
 
 
   
9  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com 
 
 
• Use Policy Management to make or define and enforce your own policies fro 
configuring and managing SQL Server across the enterprise, eg. Policy that Prefixes for 
stored procedures should be sp. 
 
• Use sparse columns to reduce the space requirements for null values. (Read  More  Here) 
 
• Use MERGE Statement to implement multiple DML operations instead of writing 
separate INSERT, UPDATE, DELETE statements.  
 
• When some particular records are retrieved frequently, apply Filtered Index to improve 
query performace, faster retrieval and reduce index maintenance costs. 
 
• Using the NOLOCK query optimizer hint is considered good practice in order to improve 
concurrency on a busy system. 
 
• EXCEPT or NOT EXIST clause can be used in place of LEFT JOIN or NOT IN for better 
peformance.  
Example:  
SELECT   EmpNo, EmpName 
FROM     EmployeeRecord 
WHERE    Salary > 1000 AND Salary 
NOT IN (SELECT   Salary 
FROM     EmployeeRecord 
WHERE    Salary > 2000); 
 
  (Recomended) 
SELECT   EmpNo, EmpName 
FROM     EmployeeRecord 
WHERE    Salery > 1000 
EXCEPT 
SELECT   EmpNo, EmpName 
FROM     EmployeeRecord 
WHERE    Salery > 2000 
ORDER BY   EmpName; 
 
 
 
 
 
 

Contenu connexe

Tendances

SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...Michael Noel
 
MySQL 5.6, news in 5.7 and our HA options
MySQL 5.6, news in 5.7 and our HA optionsMySQL 5.6, news in 5.7 and our HA options
MySQL 5.6, news in 5.7 and our HA optionsTed Wennmark
 
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...Keith Hollman
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesTarique Saleem
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQLTed Wennmark
 
Oracle 10g introduction
Oracle 10g introductionOracle 10g introduction
Oracle 10g introductionsagaroceanic11
 
Posscon my sql56
Posscon my sql56Posscon my sql56
Posscon my sql56Dave Stokes
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise MonitorTed Wennmark
 
Less04 database instance
Less04 database instanceLess04 database instance
Less04 database instanceAmit Bhalla
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)Gustavo Rene Antunez
 
MySQL Enterprise Backup & Oracle Secure Backup
MySQL Enterprise Backup &  Oracle Secure BackupMySQL Enterprise Backup &  Oracle Secure Backup
MySQL Enterprise Backup & Oracle Secure BackupSanjay Manwani
 
MySQL Features & Implementation
MySQL Features & ImplementationMySQL Features & Implementation
MySQL Features & ImplementationOSSCube
 
Oracle Cloud is Best for Oracle Database - High Availability
Oracle Cloud is Best for Oracle Database - High AvailabilityOracle Cloud is Best for Oracle Database - High Availability
Oracle Cloud is Best for Oracle Database - High AvailabilityMarkus Michalewicz
 
MySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersMySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersRonald Bradford
 
AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...
AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...
AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...Michael Noel
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 UpdatesDave Stokes
 
Building the Perfect SharePoint 2010 Farm - SPS Sacramento
Building the Perfect SharePoint 2010 Farm - SPS SacramentoBuilding the Perfect SharePoint 2010 Farm - SPS Sacramento
Building the Perfect SharePoint 2010 Farm - SPS SacramentoMichael Noel
 
oda-x5-2-DATA SHEET
oda-x5-2-DATA SHEEToda-x5-2-DATA SHEET
oda-x5-2-DATA SHEETDaryll Whyte
 
Oracle ofa for windows tips
Oracle ofa for windows tipsOracle ofa for windows tips
Oracle ofa for windows tipsYesid Pacheco
 
Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011
Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011
Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011Michael Noel
 

Tendances (20)

SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
SharePoint 2010 High Availability and Disaster Recovery - SharePoint Connecti...
 
MySQL 5.6, news in 5.7 and our HA options
MySQL 5.6, news in 5.7 and our HA optionsMySQL 5.6, news in 5.7 and our HA options
MySQL 5.6, news in 5.7 and our HA options
 
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
Moodle Moot Spain: Moodle Available and Scalable with MySQL HA - InnoDB Clust...
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New Features
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
Oracle 10g introduction
Oracle 10g introductionOracle 10g introduction
Oracle 10g introduction
 
Posscon my sql56
Posscon my sql56Posscon my sql56
Posscon my sql56
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise Monitor
 
Less04 database instance
Less04 database instanceLess04 database instance
Less04 database instance
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)
 
MySQL Enterprise Backup & Oracle Secure Backup
MySQL Enterprise Backup &  Oracle Secure BackupMySQL Enterprise Backup &  Oracle Secure Backup
MySQL Enterprise Backup & Oracle Secure Backup
 
MySQL Features & Implementation
MySQL Features & ImplementationMySQL Features & Implementation
MySQL Features & Implementation
 
Oracle Cloud is Best for Oracle Database - High Availability
Oracle Cloud is Best for Oracle Database - High AvailabilityOracle Cloud is Best for Oracle Database - High Availability
Oracle Cloud is Best for Oracle Database - High Availability
 
MySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersMySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and Developers
 
AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...
AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...
AUDWC 2016 - Using SQL Server 20146 AlwaysOn Availability Groups for SharePoi...
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 Updates
 
Building the Perfect SharePoint 2010 Farm - SPS Sacramento
Building the Perfect SharePoint 2010 Farm - SPS SacramentoBuilding the Perfect SharePoint 2010 Farm - SPS Sacramento
Building the Perfect SharePoint 2010 Farm - SPS Sacramento
 
oda-x5-2-DATA SHEET
oda-x5-2-DATA SHEEToda-x5-2-DATA SHEET
oda-x5-2-DATA SHEET
 
Oracle ofa for windows tips
Oracle ofa for windows tipsOracle ofa for windows tips
Oracle ofa for windows tips
 
Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011
Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011
Building the Perfect SharePoint 2010 Farm - SharePoint Saturday NYC 2011
 

En vedette

malhaznikfgf;kg;ll;rmmkfklgjlksjdkgksld
malhaznikfgf;kg;ll;rmmkfklgjlksjdkgksldmalhaznikfgf;kg;ll;rmmkfklgjlksjdkgksld
malhaznikfgf;kg;ll;rmmkfklgjlksjdkgksldmalhazni
 
moi prezentasiu
moi prezentasiumoi prezentasiu
moi prezentasiumalhazni
 
Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...
Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...
Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...davsor1
 
Assessment 709
Assessment 709Assessment 709
Assessment 709darias60
 
Centrale di compressione lego
Centrale di compressione legoCentrale di compressione lego
Centrale di compressione legoStefano Maronese
 
Security Considerations on Hybrid Cloud
Security Considerations on Hybrid CloudSecurity Considerations on Hybrid Cloud
Security Considerations on Hybrid Clouddavsor1
 
Iraq_infant_mortality_paper
Iraq_infant_mortality_paperIraq_infant_mortality_paper
Iraq_infant_mortality_paperKayvon Alizadeh
 
Grammatisk oversigt Engelsk
Grammatisk oversigt EngelskGrammatisk oversigt Engelsk
Grammatisk oversigt EngelskSøren Bekhøj
 
Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...
Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...
Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...Stefano Maronese
 
2013 ks2 grammar, punctuation spelling mark schemes
2013 ks2 grammar, punctuation spelling mark schemes2013 ks2 grammar, punctuation spelling mark schemes
2013 ks2 grammar, punctuation spelling mark schemesmaddiemidge1
 
World history chapter 22 notes
World history chapter 22 notesWorld history chapter 22 notes
World history chapter 22 notesannie1026
 
Antepartum haemorrhage s
Antepartum haemorrhage  sAntepartum haemorrhage  s
Antepartum haemorrhage sDr E.W Ugboma
 
actin and myosin interaction
actin and myosin interactionactin and myosin interaction
actin and myosin interactionMuhammad Nabeel
 
Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...
Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...
Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...Stefano Maronese
 
Cataract surgery types and per, early post op and late post op complications
Cataract surgery types and per, early post op and late post op complicationsCataract surgery types and per, early post op and late post op complications
Cataract surgery types and per, early post op and late post op complicationsMuhammad Nabeel
 

En vedette (16)

Group 8 facebook
Group 8 facebookGroup 8 facebook
Group 8 facebook
 
malhaznikfgf;kg;ll;rmmkfklgjlksjdkgksld
malhaznikfgf;kg;ll;rmmkfklgjlksjdkgksldmalhaznikfgf;kg;ll;rmmkfklgjlksjdkgksld
malhaznikfgf;kg;ll;rmmkfklgjlksjdkgksld
 
moi prezentasiu
moi prezentasiumoi prezentasiu
moi prezentasiu
 
Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...
Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...
Il ruolo degli intermediari nell'ecosistema dell'innovazione aperta: l'approc...
 
Assessment 709
Assessment 709Assessment 709
Assessment 709
 
Centrale di compressione lego
Centrale di compressione legoCentrale di compressione lego
Centrale di compressione lego
 
Security Considerations on Hybrid Cloud
Security Considerations on Hybrid CloudSecurity Considerations on Hybrid Cloud
Security Considerations on Hybrid Cloud
 
Iraq_infant_mortality_paper
Iraq_infant_mortality_paperIraq_infant_mortality_paper
Iraq_infant_mortality_paper
 
Grammatisk oversigt Engelsk
Grammatisk oversigt EngelskGrammatisk oversigt Engelsk
Grammatisk oversigt Engelsk
 
Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...
Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...
Biofuel Project: an anlysis to substitute 10% italian petrol by mean of non-f...
 
2013 ks2 grammar, punctuation spelling mark schemes
2013 ks2 grammar, punctuation spelling mark schemes2013 ks2 grammar, punctuation spelling mark schemes
2013 ks2 grammar, punctuation spelling mark schemes
 
World history chapter 22 notes
World history chapter 22 notesWorld history chapter 22 notes
World history chapter 22 notes
 
Antepartum haemorrhage s
Antepartum haemorrhage  sAntepartum haemorrhage  s
Antepartum haemorrhage s
 
actin and myosin interaction
actin and myosin interactionactin and myosin interaction
actin and myosin interaction
 
Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...
Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...
Master thesis in biorefinery pathways selection using MILP with Integer-Cuts ...
 
Cataract surgery types and per, early post op and late post op complications
Cataract surgery types and per, early post op and late post op complicationsCataract surgery types and per, early post op and late post op complications
Cataract surgery types and per, early post op and late post op complications
 

Similaire à Sql server guidelines

Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!SolarWinds
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptxKulbir4
 
Oracle Database 11g SQL Tuning Workshop - Student Guide.pdf
Oracle Database 11g SQL Tuning Workshop - Student Guide.pdfOracle Database 11g SQL Tuning Workshop - Student Guide.pdf
Oracle Database 11g SQL Tuning Workshop - Student Guide.pdfRajendra Jain
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAsBen Krug
 
Compare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdf
Compare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdfCompare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdf
Compare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdfarihantplastictanksh
 
Azure + DataStax Enterprise (DSE) Powers Office365 Per User Store
Azure + DataStax Enterprise (DSE) Powers Office365 Per User StoreAzure + DataStax Enterprise (DSE) Powers Office365 Per User Store
Azure + DataStax Enterprise (DSE) Powers Office365 Per User StoreDataStax Academy
 
Sql training
Sql trainingSql training
Sql trainingpremrings
 
Andrewfraserdba.com training sql_training
Andrewfraserdba.com training sql_trainingAndrewfraserdba.com training sql_training
Andrewfraserdba.com training sql_trainingmark jerald Canal
 
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...LarryZaman
 
Apache Kudu: Technical Deep Dive


Apache Kudu: Technical Deep Dive

Apache Kudu: Technical Deep Dive


Apache Kudu: Technical Deep Dive

Cloudera, Inc.
 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMonica Li
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMonica Li
 
Less01 db architecture
Less01 db architectureLess01 db architecture
Less01 db architectureImran Ali
 
Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroringwebhostingguy
 
What's New in MySQL 5.7
What's New in MySQL 5.7What's New in MySQL 5.7
What's New in MySQL 5.7Olivier DASINI
 
Intro to Azure SQL database
Intro to Azure SQL databaseIntro to Azure SQL database
Intro to Azure SQL databaseSteve Knutson
 
Azure Synapse Analytics Overview (r2)
Azure Synapse Analytics Overview (r2)Azure Synapse Analytics Overview (r2)
Azure Synapse Analytics Overview (r2)James Serra
 
Azure Nights August2017
Azure Nights August2017Azure Nights August2017
Azure Nights August2017Michael Frank
 
Automatic upgrade and new error logging in my sql 8.0
Automatic upgrade and new error logging in my sql 8.0Automatic upgrade and new error logging in my sql 8.0
Automatic upgrade and new error logging in my sql 8.0Ståle Deraas
 

Similaire à Sql server guidelines (20)

Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
Hi! Ho! Hi! Ho! SQL Server on Linux We Go!
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Oracle Database 11g SQL Tuning Workshop - Student Guide.pdf
Oracle Database 11g SQL Tuning Workshop - Student Guide.pdfOracle Database 11g SQL Tuning Workshop - Student Guide.pdf
Oracle Database 11g SQL Tuning Workshop - Student Guide.pdf
 
Resume
ResumeResume
Resume
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
Compare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdf
Compare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdfCompare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdf
Compare the capabilities of the Microsoft Access, Microsoft SQL Serv.pdf
 
Azure + DataStax Enterprise (DSE) Powers Office365 Per User Store
Azure + DataStax Enterprise (DSE) Powers Office365 Per User StoreAzure + DataStax Enterprise (DSE) Powers Office365 Per User Store
Azure + DataStax Enterprise (DSE) Powers Office365 Per User Store
 
Sql training
Sql trainingSql training
Sql training
 
Andrewfraserdba.com training sql_training
Andrewfraserdba.com training sql_trainingAndrewfraserdba.com training sql_training
Andrewfraserdba.com training sql_training
 
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
Business_Continuity_Planning_with_SQL_Server_HADR_options_TechEd_Bangalore_20...
 
Apache Kudu: Technical Deep Dive


Apache Kudu: Technical Deep Dive

Apache Kudu: Technical Deep Dive


Apache Kudu: Technical Deep Dive


 
MOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical ExamplesMOUG17: SQLT Utility for Tuning - Practical Examples
MOUG17: SQLT Utility for Tuning - Practical Examples
 
MOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your DataMOUG17: DB Security; Secure your Data
MOUG17: DB Security; Secure your Data
 
Less01 db architecture
Less01 db architectureLess01 db architecture
Less01 db architecture
 
Effective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database MirroringEffective Usage of SQL Server 2005 Database Mirroring
Effective Usage of SQL Server 2005 Database Mirroring
 
What's New in MySQL 5.7
What's New in MySQL 5.7What's New in MySQL 5.7
What's New in MySQL 5.7
 
Intro to Azure SQL database
Intro to Azure SQL databaseIntro to Azure SQL database
Intro to Azure SQL database
 
Azure Synapse Analytics Overview (r2)
Azure Synapse Analytics Overview (r2)Azure Synapse Analytics Overview (r2)
Azure Synapse Analytics Overview (r2)
 
Azure Nights August2017
Azure Nights August2017Azure Nights August2017
Azure Nights August2017
 
Automatic upgrade and new error logging in my sql 8.0
Automatic upgrade and new error logging in my sql 8.0Automatic upgrade and new error logging in my sql 8.0
Automatic upgrade and new error logging in my sql 8.0
 

Dernier

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 

Dernier (20)

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 

Sql server guidelines

  • 1.       1  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      INDEX  Guidelines for SQL SERVER  1  Important Guidelines for SQL Server………………………….. 2                Notice:  All rights reserved worldwide. No part of this book may be reproduced or copied or  translated in any form by any electronic or mechanical means (including photocopying,  recording, or information storage and retrieval) without permission in writing from the  publisher, except for reading and browsing via the World Wide Web. Users are not permitted  to mount this file on any network servers.    For more information send email to: pinal@sqlauthority.com       
  • 2.       2  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      Important Guidelines for SQL SERVER  • Use "Pascal" notation for SQL server Objects Like Tables, Views, Stored Procedures.  Also tables and views should have ending "s".  Example:   UserDetails   Emails    • If you have big subset of table group than it makes sense to give prefix for this table  group. Prefix should be separated by _.   Example:  Page_ UserDetails  Page_ Emails    • Use following naming convention for Stored Procedure. sp<Application  Name>_[<group name >_]<action type><table name or logical instance> Where action  is: Get, Delete, Update, Write, Archive, Insert... i.e. verb   Example:   spApplicationName_GetUserDetails   spApplicationName_UpdateEmails    • Use following Naming pattern for triggers: TR_<TableName>_<action><description>   Example:   TR_Emails_LogEmailChanges   TR_UserDetails_UpdateUserName    • Indexes : IX_<tablename>_<columns separated by_>   Example:   IX_UserDetails_UserID    • Primary Key : PK_<tablename>   Example:   PK_UserDetails   PK_ Emails     
  • 3.       3  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • Foreign Key : FK_<tablename_1>_<tablename_2>   Example:   FK_UserDetails_Emails    • Default: DF_<table name>_<column name>   Example:   DF_ UserDetails _UserName    • Normalize Database structure based on 3rd  Normalization Form. Normalization is the  process of designing a data model to efficiently store data in a database. (Read More  Here)    • Avoid use of SELECT * in SQL queries. Instead practice writing required column names  after SELECT statement.  Example:  SELECT   Username, Password  FROM    UserDetails    • Avoid using temporary tables and derived tables as it uses more disks I/O. Instead use  CTE (Common Table Expression); its scope is limited to the next statement in SQL query.  (Read More Here)    • Use SET NOCOUNT ON at the beginning of SQL Batches, Stored Procedures and Triggers.  This improves the performance of Stored Procedure. (Read More Here)    • Properly format SQL queries using indents.  Example: Wrong Format   SELECT Username, Password FROM UserDetails ud INNER JOIN Employee e ON e.EmpID = ud.UserID    Example: Correct Format  SELECT   Username, Password   FROM    UserDetails ud   INNER JOIN  Employee e ON e.EmpID = ud.UserID     
  • 4.       4  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • Practice writing Upper Case for all SQL keywords.  Example:  SELECT, UPDATE, INSERT, WHERE, INNER JOIN, AND, OR, LIKE.    • There must be PRIMARY KEY in all the tables of database with column name ID. It is  common practice to use Primary Key as IDENTITY column.    • If “One Table” references “Another Table” than the column name used in reference  should use the following rule :  Column of Another Table : <OneTableName> ID  Example:  If User table references Employee table than the column name used in reference should  be UserID where User is table name and ID primary column of User table and UserID is  reference column of Employee table.    • Columns with Default value constraint should not allow NULLs.    • Practice using PRIMARY key in WHERE condition of UPDATE or DELETE statements as  this will avoid error possibilities.    • Always create stored procedure in same database where its relevant table exists  otherwise it will reduce network performance.    • Avoid server‐side Cursors as much as possible, instead use SELECT statement. If you  need to use cursor then replace it with WHILE loop (or read next suggestion).    • Instead of using LOOP to insert data from Table B to Table A, try to use SELECT  statement with INSERT statement. (Read More Here)    INSERT INTO Table A (column1, column2)  SELECT column1, column2  FROM Table B  WHERE ….   
  • 5.       5  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • Avoid using spaces within the name of database objects; this may create issues with  front‐end data access tools and applications. If you need spaces in your database object  name then will accessing it surround the database object name with square brackets.  Example:  [Order Details]    • Do not use reserved words for naming database objects, as that can lead to some  unpredictable situations. (Read More Here)    • Practice writing comments in stored procedures, triggers and SQL batches, whenever  something is not very obvious, as it won’t impact the performance.    • Do not use wild card characters at the beginning of word while search using LIKE  keyword as it results in Index scan.    • Indent code for better readability. (Example)    • While using JOINs in your SQL query always prefix column name with the table name.  (Example). If additionally require then prefix Table name with ServerName,  DatabaseName, DatabaseOwner. (Example)    • Default constraint must be defined at the column level. All other constraints must be  defined at the table level. (Read More Here)    • Avoid using rules of database objects instead use constraints.    • Do not use the RECOMPILE option for Stored Procedure as it reduces the performance.    • Always put the DECLARE statements at the starting of the code in the stored procedure.  This will make the query optimizer to reuse query plans. (Example)    • Put the SET statements in beginning (after DECLARE) before executing code in the  stored procedure. (Example)    • Use BEGIN…END blocks only when multiple statements are present within a conditional  code segment. (Read More Here) 
  • 6.       6  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • To express apostrophe within a string, nest single quotes (two single quotes).  Example:  SET @sExample = 'SQL''s Authority'    • When working with branch conditions or complicated expressions, use parenthesis to  increase readability.  Example:  IF ((SELECT 1    FROM TableName   WHERE 1=2) ISNULL)    • To mark single line as comment use (‐‐) before statement. To mark section of code as  comment use (/*...*/).    • Avoid the use of cross joins if possible. (Read More Here)    • If there is no need of resultset then use syntax that doesn’t return a resultset.  IF EXISTS (SELECT  1          FROM  UserDetails          WHERE  UserID = 50)      Rather than,  IF EXISTS (SELECT  COUNT (UserID)            FROM  UserDetails          WHERE  UserID = 50)    • Use graphical execution plan in Query Analyzer or SHOWPLAN_TEXT or  SHOWPLAN_ALL commands to analyze SQL queries. Your queries should do an “Index  Seek” instead of an “Index Scan” or a “Table Scan”. (Read More Here)    • Do not prefix stored procedure names with “SP_”, as “SP_” is reserved for system  stored procedures.  Example:   SP<App Name>_ [<Group Name >_] <Action><table/logical instance> 
  • 7.       7  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • Incorporate your frequently required, complicated joins and calculations into a view so  that you don’t have to repeat those joins/calculations in all your queries. Instead, just  select from the view. (Read More Here)    • Do not query / manipulate the data directly in your front end application, instead create  stored procedures, and let your applications to access stored procedure.    • Avoid using ntext, text, and image data types in new development work. Use nvarchar  (max), varchar (max), and varbinary (max) instead.    • Do not store binary or image files (Binary Large Objects or BLOBs) inside the database.  Instead, store the path to the binary or image file in the database and use that as a  pointer to the actual file stored on a server.    • Use the CHAR datatype for a non‐nullable column, as it will be the fixed length column,  NULL value will also block the defined bytes.    • Avoid using dynamic SQL statements. Dynamic SQL tends to be slower than static SQL,  as SQL Server generate execution plan every time at runtime.    • Minimize the use of Nulls. Because they incur more complexity in queries and updates.  ISNULL and COALESCE functions are helpful in dealing with NULL values    • Use Unicode datatypes, like NCHAR, NVARCHAR or NTEXT if it needed, as they use  twice as much space as non‐Unicode datatypes.    • Always use column list in INSERT statements of SQL queries. This will avoid problem  when table structure changes.    • Perform all referential integrity checks and data validations using constraints instead of  triggers, as they are faster. Limit the use of triggers only for auditing, custom tasks, and  validations that cannot be performed using constraints.    • Always access tables in the same order in all stored procedure and triggers consistently.  This will avoid deadlocks. (Read More Here)   
  • 8.       8  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • Do not call functions repeatedly in stored procedures, triggers, functions and batches,  instead call the function once and store the result in a variable, for later use.    • With Begin and End Transaction always use global variable @@ERROR, immediately  after data manipulation statements (INSERT/UPDATE/DELETE), so that if there is an  Error the transaction can be rollback.    • Excessive usage of GOTO can lead to hard‐to‐read and understand code.    • Do not use column numbers in the ORDER BY clause; it will reduce the readability of SQL  query.  Example: Wrong Statement  SELECT   UserID, UserName, Password  FROM    UserDetails  ORDER BY  2    Example: Correct Statement  SELECT   UserID, UserName, Password  FROM    UserDetails  ORDER BY  UserName    • To avoid trips from application to SQL Server, we should retrive multiple resultset from  single Stored Procedure instead of using output param.    • The RETURN statement is meant for returning the execution status only, but not data. If  you need to return data, use OUTPUT parameters.    • If stored procedure always returns single row resultset, then consider returning the  resultset using OUTPUT parameters instead of SELECT statement, as ADO handles  OUTPUT parameters faster than resultsets returned by SELECT statements.    • Effective indexes are one of the best ways to improve performance in a database  application.    • BULK  INSERT  command  helps  to  import  a  data  file  into  a  database  table  or  view  in   a  user‐specified  format.   
  • 9.       9  © Copyright 2000-2008 Pinal Dave. All Rights Reserved. SQLAuthority.com      • Use Policy Management to make or define and enforce your own policies fro  configuring and managing SQL Server across the enterprise, eg. Policy that Prefixes for  stored procedures should be sp.    • Use sparse columns to reduce the space requirements for null values. (Read  More  Here)    • Use MERGE Statement to implement multiple DML operations instead of writing  separate INSERT, UPDATE, DELETE statements.     • When some particular records are retrieved frequently, apply Filtered Index to improve  query performace, faster retrieval and reduce index maintenance costs.    • Using the NOLOCK query optimizer hint is considered good practice in order to improve  concurrency on a busy system.    • EXCEPT or NOT EXIST clause can be used in place of LEFT JOIN or NOT IN for better  peformance.   Example:   SELECT   EmpNo, EmpName  FROM     EmployeeRecord  WHERE    Salary > 1000 AND Salary  NOT IN (SELECT   Salary  FROM     EmployeeRecord  WHERE    Salary > 2000);      (Recomended)  SELECT   EmpNo, EmpName  FROM     EmployeeRecord  WHERE    Salery > 1000  EXCEPT  SELECT   EmpNo, EmpName  FROM     EmployeeRecord  WHERE    Salery > 2000  ORDER BY   EmpName;