SQL_Server_2005_Coding_Standards_v1[1].0
- 格式:pdf
- 大小:257.64 KB
- 文档页数:12
实验项目名称SQL Server 2005管理工具的基本使用方法学号:姓名:专业:指导老师:一.实验目的:1.了解SQL Server 2005安装对软、硬件的要求,学会安装方法。
2.了解SOL Server的注册和配置方法。
3.了解SQL Server 2005包含的主要组件及其功能。
4.熟悉SQL Server 2005管理平台的界面及基本使用方法。
5. 了解数据库及其对象。
6. 了解在SQL Server 2005管理平台中执行SQL语句的方法。
二.预习要求:1.了解SQL Server 2005实例含义,了解SQL Server 2005支持的身份验证模式。
2.了解SQL Serve 2005各组件的主要功能。
3. 了解在查询编辑器中执行SQL语句的方法。
三.实验介绍:1.配置数据库。
通过“开始”→“程序”→Microsoft SQL Server 2005 →“配置工具”->Server Configuration Manager菜单项,打开“SQL Server配置管理器”窗口,在界面左边的树目录中选择“SQL Server 2005服务”。
在右边的项列表区中选择SQL server服务。
并通过该窗口“启动服务”和“停止服务”图标来启动和停止SOL Server服务。
暂停服务:启动服务:2. 查看SQL Server的相关信息。
(1)在SQL Server管理平台的对象资源管理器中打开本地服务器的属性对话框,查看以下信息:产品名称、主机操作系统、产品的版本、操作平台、主机内存等。
(2)在SQL Server 管理平台中,注册服务器。
查看本地已注册的SQL Server。
搜索网络上另一台计算机,并且注册该机上的SQL Server,注册时使用“Windows认证模式”或“用我的SQL Server身份认证”的连接方式。
3. 利用SQL Server管理平台访问数据库(1)添加数据库文件。
sqlserver2005标准版SQL Server 2005标准版是微软推出的一款关系型数据库管理系统,它具有稳定性高、性能优越、安全性强等特点,被广泛应用于企业级数据库管理和数据处理领域。
本文将对SQL Server 2005标准版的特点、安装与配置、管理与维护等方面进行详细介绍,希望能够帮助读者更好地了解和应用SQL Server 2005标准版。
一、特点。
SQL Server 2005标准版具有以下几个显著特点:1.1 高性能。
SQL Server 2005标准版采用了先进的数据库引擎和优化技术,能够快速高效地处理大规模数据,保证系统的稳定性和性能。
1.2 安全性强。
SQL Server 2005标准版提供了多层次的安全保障机制,包括访问控制、数据加密、安全审计等功能,保护数据不受未经授权的访问和篡改。
1.3 可靠性高。
SQL Server 2005标准版具有自动故障恢复和数据备份恢复功能,能够保证数据的完整性和可靠性。
1.4 管理与维护简便。
SQL Server 2005标准版提供了直观友好的管理界面和丰富的管理工具,使数据库的管理和维护变得简单易行。
二、安装与配置。
在安装SQL Server 2005标准版之前,需要确保系统符合相应的硬件和软件要求,包括操作系统版本、CPU、内存、磁盘空间等。
安装过程中,需要按照提示逐步进行,包括选择安装类型、指定实例名称、配置身份验证模式、设置管理员账户等。
安装完成后,还需要进行相应的配置,包括网络配置、安全配置、数据库引擎配置等,以确保SQL Server 2005标准版能够正常运行。
三、管理与维护。
SQL Server 2005标准版的管理与维护包括数据库的创建与删除、用户权限的管理、数据备份与恢复、性能监控与优化等方面。
在数据库的创建与删除过程中,需要考虑数据库的结构设计、数据类型选择、约束条件设置等,以满足实际业务需求。
在用户权限的管理过程中,需要设定用户的访问权限、操作权限和对象权限,保证数据的安全性和完整性。
数据库技术与应用实践教程-SQL Server 2005上机实验指导(实验思考)—参考答案实验1:安装及管理工具使用略。
实验2:SQL Server数据库的管理二、实验内容及步骤4.单击“新建查询”打开查询设计器窗口,在查询设计器窗口中使用Transact-SQL语句CREATE DATABASE创建studb 数据库。
然后通过系统存储过程sp_helpdb查看系统中的数据库信息。
CREATE DATABASE studbON( NAME=studb_dat,FILENAME='C:\DataBase\studb.mdf')EXEC sp_helpdb5.在查询设计器中使用Transact-SQL语句ALTER DATABASE修改studb数据库的设置,指定数据文件大小为5MB,最大文件大小为20MB,自动递增大小为1MB。
ALTER DATABASE studbMODIFY FILE (NAME=studb_data, SIZE = 5MB, MAXSIZE = 20MB, FILEGROWTH = 1MB)6.在查询设计器中为studb数据库增加一个日志文件,命名为studb_Log2,大小为5MB,最大文件大小为10MB。
ALTER DATABASE studbADD LOG FILE(NAME = studb_log2, FILENAME=studb_log2.ldf, SIZE = 5MB, MAXSIZE = 10MB)8.使用Transact-SQL语句DROP DATABASE删除student_db数据库。
DROP DATABASE student_db实验3 SQL Server数据表的管理二、实验内容及步骤5.使用Transact-SQL语句CREATE TABLE在studentsdb 数据库中创建grade表。
CREATE TABLE grade ([学号] [char] (4) NULL,[课程编号] [char] (4) NULL ,[分数] [char] (5) NULL) ON [PRIMARY]8.使用Transact-SQL语句INSERT INTO...V ALUES向studentsdb数据库的grade表插入数据:学号为0004,课程编号为0001,分数为80。
虚拟机安装SQL2005步骤图解
SQL Server 2005共两个安装包。
1、创建虚拟光驱
2、选择第一个安装包
3、点“服务器组件、工具、联机丛书和示例(C)”
4、接受安装条款,然后“下一步”
5、开始安装
6、选择“下一步”
7、扫描计算机配置
8、扫描完成后,单击“下一步”
9、单击“下一步”
10、注册信息,填写姓名和公司
11、选择你要安装的组建,然后“下一步”
12、选择“默认实例”,然后“下一步”
13、选择“使用内置系统账户”,然后“下一步”
14、选择你想要的身份验证模式
15、单击“下一步”
16、选择“安装默认设置”,然后“下一步”
17、不用选择,然后“下一步”
18、开始安装
19、安装过程无需任何操作
20、上面的安装顺利完成后,打开SQL Server 2005的第二个安装包。
点“仅工具、联机丛书和示例(T) ”
21、点“仅工具、联机丛书和示例(T) ”
22、选择安装路径,然后“下一步”
23、计算安装空间
24、单击“下一步”
25、单击“下一步”安装完成。
SQL Server 2005 配置说明一、安装SQL Server 2005数据库目前,64位系统上安装的SQL Server 2005数据库,都是由Microsoft Visual Studio 2008安装的Express版本。
安装过程如下:1.先安装虚拟光驱daemo-x64.exe,安装过程中,会提示重新启动,重新启动完成后,就会安装虚拟光驱完成。
这时,会在屏幕右下角出现红色闪电图标。
左键点击图标,选择安装VS 2008的虚拟镜像文件zmvspro8.iso。
如图:使用虚拟光驱选择安装VS2008的虚拟光驱镜像文件2.安装VS2008,在选择好VS2008镜像文件后。
打开我的电脑,选择”DVD 驱动器(G:)”盘(可能根据不同的电脑,虚拟光驱的名字不一样),进入后,选择Autorun.exe执行安装VS2008。
根据安装提示一步一步安装完成,这样数据库就可以安装完成了。
注意,在选择安装时,选择完全安装(FULL),以防环境不一样,导致数据库运行出现问题。
如图红色区域:选择完全安装即FULL安装3.安装数据库管理工具SQL Server 2005 Management studio。
由于是从VS2008中安装的数据库,所以安装完成的数据库中是没有数据库管理工具,我们要自己安装个数据库管理工具。
安装管理工具的软件从相关人员索要。
执行“SQLServer2005_SSMSEE_x64.msi”,根据安装提示一步步就可以安装成功,安装成功后,可以查看管理数据库。
如图所示:成功安装SQL Server 2005和数据库管理工具,红色为管理工具4.查看数据库。
在使用数据库前,先要确认数据库服务正常启动。
点击《开始》->《程序》->《Microsoft SQL Server 2005》->《Configuration Tools》->《SQL Server Configuration Manager》后,会出现数据库配置管理对话框,点击左边树状图中“SQL Server 2005 Services”,在右边查看“SQL Server(SQLEXPRESS)”的图标,是否有个绿色的小箭头,如果有则说明数据库服务正常运行。
sql2005标准版SQL Server 2005标准版是由Microsoft开发的关系型数据库管理系统(RDBMS)。
下面我将从多个角度来回答有关SQL Server 2005标准版的问题。
1. 什么是SQL Server 2005标准版?SQL Server 2005标准版是SQL Server 2005系列中的一个版本,它提供了基本的数据库管理功能,适用于中小型企业和个人使用。
它具有许多核心功能,如数据存储、查询、事务处理和安全性管理等。
2. SQL Server 2005标准版的特点有哪些?SQL Server 2005标准版具有以下特点:数据库引擎,提供可靠的数据存储和管理功能,支持关系型数据模型。
查询处理,具备强大的查询处理能力,包括索引、视图、存储过程等。
事务处理,支持ACID(原子性、一致性、隔离性和持久性)事务,确保数据的完整性和一致性。
安全性管理,提供用户和权限管理功能,保护数据库免受未经授权的访问。
可伸缩性,支持多用户并发访问,能够处理大量数据和高负载。
可编程性,提供存储过程、触发器和函数等编程功能,增强数据库的灵活性和扩展性。
3. SQL Server 2005标准版的系统要求是什么?SQL Server 2005标准版的系统要求包括:操作系统,支持Windows Server 2003、Windows Server 2008和Windows XP等操作系统。
处理器,建议使用1GHz或更高速度的处理器。
内存,建议至少512MB的内存,但更大的内存可以提供更好的性能。
存储空间,建议至少1GB的可用磁盘空间用于安装和数据库存储。
4. SQL Server 2005标准版的优势和劣势是什么?SQL Server 2005标准版的优势包括:相对较低的成本,相比于其他版本的SQL Server,标准版的价格更为经济实惠。
良好的性能,标准版提供了强大的查询处理和事务处理功能,能够满足大部分中小型企业的需求。
Eclipse连接SQL Server 2005数据库在连接数据库之前必须保证SQL Server 2005是采用SQL Server身份验证方式而不是windows身份验证方式。
如果在安装时选用了后者,则重新设置如下:1.打开SQL Server 2005,图1右击最上面的服务器,选择属性——>安全性,在右边框中选择SQL Server和Windows身份验证模式,如下图,最后点确定。
图22.选择“安全性”中的登录名中的sa,右击选择“属性”,出现下图;图3在图3,选择常规,在右边输入登录名sa,输入密码与确认密码123456,再在左边选择状态,在登录中设“启用”,如图4图4保证SQL Server 2005是采用SQL Server身份验证方式下开始配置:一、SQL Server 2005的配置:1、安装好SQL Server 2005后,运行开始→ 所有程序→ Microsoft SQL Server 2005 → 配置工具→ SQL Server Configuration Manager,在打开的窗口的左边找到 MSSQLSERVER 的协议,在右边右单击 TCP/IP,选择已启用。
如果Named Pipes 未启用也设为启用。
如图5所示:图52、双击图5右边的 TCP/IP,在弹出的窗口中选择 IP地址标签,把 IPAll 中的 TCP端口设成 1433,并将上方所有的已启用选项设置成是。
如图6所示:图63、运行开始→ 所有程序→ Microsoft SQL Server 2005 → 配置工具→ SQL Server 外围应用配置器,在打开的窗口中选择服务和连接的外围应用配置器,在打开的窗口左边选择远程连接,在右边选择同时使用TCP/IP和named pipes(B),然后点击应用。
如图7所示:图74、然后重启电脑,重启完毕后,接下来使用命令测试1433端口是否打开。
5、开始菜单→ 运行cmd → 在命令提示符下输入:netstat –an。
前天安装IBM3650服务器数据库,处理器是interXeon5649 6核的,安装了win server 2003的系统,需要来安装SQL Server 2005,系统是新做的,很干净。
首先,安装了.netFramework2.0及IIS,拿来一版以前装过,而且没有问题的SQL Server 2005企业版,在安装到大约一半的时候,提示错误:“SQLServer 服务部无法启动”。
起初怀疑过权限的问题,在网上寻找了一些解决办法,都不行;在卸载重装SQL Server 2005两三次后,突然看到微软官网上的一条技术帮助信息,/kb/954835/zh-cn。
意思是,在具有多核处理器的计算机,您可能无法安装SQL Server 2005,而曙光天阔A620R-H服务器搭载一颗6核CPU,所以不能安装SQL Server 2005,得到这个答案的确让人沮丧,不禁感慨微软的万恶。
继续向下看,这个问题的解决办法如下:SQL server服务无法启动的原因分析:在安装SQL 2005标准版(不多于四个CPU)和企业版(无限制)时,CPU的总核数必须是2的n次方。
即核心数为1,2,4,8,16,32依次类推。
因BL680C核心数为6x4=24,所以不能正常安装。
当将核心数更改为8,16时,顺利完成安装。
说实话,觉得这么做很不可思议,居然与核心数有关。
继续吧,按照上面所说的步骤,修改了“/NUMPROC”,此处我先说一下,我把“/NUMPROC”改为1,4,8都不能正常安装SQL Server 2005,唯独改为2后,可以正常安装。
“/NUMPROC”改为2后,重启服务器,可以在任务管理器中看到,原来的12核心,已经变为2个核心。
用Windows Installer CleanUP将SQL Server 2005删掉,再删掉注册表中的HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQLServerHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServerHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSSQLSERVER HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SQLSERVERAGENT HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSSQLSERVERADHEL PERHKEY_CURRENT_USER\Software\Microsoft\Microsoft SQLServer最后删掉C:\ProgramFiles\MicrosoftSQLServer;重启后,来重新安装SQL Server 2005,安装过程中没有再出现这个“SQLServer服务部无法启动”的问题了;然后安装SQL Server 2005 SP3补丁(据说这个补丁已解决了这个问题),但在安装补丁的过程中,程序提示“无法安装”,让人无奈!这个问题的出现让我怀疑到SQL Server 2005在重装前是否已卸载干净,于是,重做了一次win server 2003SP2的系统,再重复上述的操作,一切正常了,悬着的心也落下了。
SQLServer2005安装配置⽅法图⽂教程完美兼容Win7所有版本印象中,以前电脑不发达,⾃⾝编程经历不多的时候,由于Microsoft SQL Server版本众多,在不同版本的windows下必须要求装相应版本的SQL Server,否则有可能出现兼容性的问题,装个Microsoft SQL Server总是⾮常费劲,装完之后⽤起来,由于Microsoft SQL Server还需要⽐较多的运⾏资源,玩起来卡得不要不要的,最后Microsoft SQL Server给我留下了很难⽤很难消化的形象。
不过现在看来,Microsoft SQL Server的SQL2005版本在4G就是低配的当代,根本就不算什么。
同时这货嘴上说着有兼容性问起,其实⾝体还挺⽼实能够完美兼容Win7所有版本。
有问题也只是你安装⽅式不对⽽已。
⼀、SQL2005的安装与配置1、⾸先,这⾥的SQL2005选⽤的是:cs_sql_2005_dev_all_dvd.iso,SQL Server 2005 开发版(DVD) 。
由于版权问题,这⾥不提供下载,同微软其它软件⼀样,⼀搜⼀⼤堆。
解压之后,⾥⾯的⽬录⽐较奇怪,然⽽其中的splash.hta却是可以点击就运⾏的,如同exe可执⾏⽂件。
2、根据你系统的位数,选择相应的版本,之后来到如下图的画⾯,如果你的电脑从来没有装过VS,或者安装VS的时候没有完全安装,则先安装SQL Native Client,SQL Native Client的安装过程这⾥就不展⽰了,很脑残的,唯⼀需要注意的是,去到安装组件的那⼀步,记得全选。
如果你的电脑曾经完全安装过VS的话,选择“服务器组件、⼯具、联机丛书和⽰例”进⾏SQL Server核⼼组件的安装:3、在Win7x64系统,要安装SQL2005马上给你⼀个兼容性警告。
微软官⽅推荐的配置是WIN2008+SQL2008+VS2008,WIN7与WIN2008是同结构的,也就是WINXP与WIN2003的关系⼀样。
Coding Standards:SQL Server 2005Version: SQLSERVER2005/Coding Standards/0408/1.0Date: 30-04-08Cognizant500 Glen Pointe Center WestTeaneck, NJ 07666Ph: 201-801-0233comTABLE OF CONTENTS1. Naming Conventions (3)Tables (3)Stored Procedures (3)Triggers (3)Indexes (3)Primary Keys (3)Foreign Keys (3)Defaults (3)Columns (3)General Rules (4)Structure (4)Variables and Parameters (4)User-Defined functions (5)Others (5)2. T-SQL Guidelines (6)T-SQL Guidelines (6)Stored Procedures (SPs) (9)Views (9)Transaction Handling (9)CLR Integration guidelines (10)XML Usage Guidelines (10)References (11)Websites (11)STUDENT NOTES: (12)1. Naming ConventionsTablesRules: Pascal notation; end with a ‘s’Examples: Products, CustomersGroup related table names1Stored ProceduresRules:sp<App Name>_[<Group Name >_]<Action><table/logical instance> Examples:spOrders_GetNewOrders, spProducts_UpdateProductTriggersRules:TR_<TableName>_<action>Examples:TR_Orders_UpdateProductsIndexesRules: IX_<TableName>_<columns separated by _>Examples:IX_Products_ProductIDPrimary KeysRules:PK_<TableName>Examples:PK_ProductsForeign KeysRules:FK_<TableName1>_<TableName2>Example:FK_Products_OrderssDefaultsRules:DF_<TableName>_<ColumnName>Example:DF_Products_QuantityColumnsIf a column references another table’s column, then name it <table name>IDExample: The Customers table has an ID column.The Orders table should have a CustomerID column.General RulesDo not use spaces in the name of database objects.Do not use SQL keywords as the name of database objects. In cases where this is necessary, surround the object name with brackets, such as [Year].Do not prefix stored procedures with ‘sp_’2.Prefix table names with the owner names.StructureEach table must have a primary keyIn most cases it should be an IDENTITY column named IDNormalize data to third normal formDo not compromise on performance to reach third normal form. Sometimes, a little denormalization results in better performanceDo not use TEXT as a data type; use the maximum allowed characters of VARCHAR.In VARCHAR data columns, do not default to NULL, use an empty string insteadColumns with default values should not allow NULLsAs much as possible, create stored procedures on the same database as the main tables they will be accessingVariables and ParametersAll variables should be explicitly declared at the top of each stored procedure. Place each declaration on its own line. Explain what each parameter is for:o DECLARE @lCaseStart integer: Starting case numbero DECLARE @dStartDate datetime: First posted date of caseso DECLARE @dEndDate datetime: Last posted date of caseso DECLARE @lCaseCount integer: Running total of casesDo not make a variable name that begins with ‘@@’. Although it is a legitimate thing to do, the ‘@@’ is typically reserved for SQL Server global variables. This makes readersconfused in thinking a system variable when it is not.o DECLARE @sGoodName varchar(50): Good nameo DECLARE @@sBadName varchar(50): Bad nameNever name a variable name by its data type or by a reserved word. Use a valid business explanation of what the variable name is for.o DECLARE @dCaseOpen datetime: Date the case openedo DECLARE @datetime datetime: Bad namingA prefix for variables should contain the data type prefix, followed by what the variableor parameter is for. For user-defined types, use the prefix where the type came fromacceptable prefixes:o I: integer, smallint, tinyinto S: char, varcharo D: datetime, smalldatetimeo C: money, smallmoneyo B:bit, binary, varbinaryo F: float, realo n: decimal, numericUser-Defined functionsA user defined function should prefixed by "udf_" and then a description that logically follows the function process. The description should be proper case words with no spaces.Examples:udf_GetNextIDudf_SumOrderLinesOthersAll the database objects like tables, stored procedures, views, functions and so on should be referenced in their fully qualified name like [database].[owner].[ObjectName]. ]Example:Sales.dbo.SearchCustomer Sales.dbo.Customer. If database name is not fixed, then use [owner].[ObjectName].2. T-SQL GuidelinesT-SQL GuidelinesRetrieve only the data that is requiredA SELECT statement should retrieve only data that is necessaryColumns that are not used or already known should not be returnedSELECT * is not a good coding practice as it:o Increases network traffico Requires more buffers and processingo Could prove error prone, if the table or view definition changesMinimize the use of not equal operations, <> or !=.SQL Server has to scan a table or index to find all values to see if they are not equal to the value given in the expression.Try rephrasing the expression to use ranges.Example:Use this:SELECT Name, Description, OrderDateFROM OrdersWHERE OrderDate < ‘2005-01-01’ OR OrderDate > ‘2005-01-01’Instead of this:SELECT Name, Description, OrderDateFROM OrdersWHERE OrderDate <> ‘2005-01-01’Make sure that there are at least n-1 join criteria if there are n tables.Make sure that all tables included in the statement are joined. Make sure that only tables that Have columns in the select clauseHave columns referenced in the where clauseAllow two unrelated tables to be joined together are includedEnsure columns with similar data type are used when using JOINSPerformance suffers when non-identical columns are compared.SQL Server needs an implicit conversion between the two types.Performance is better when the tables being joined are defined with identical types.This prevents implicit data conversions by the query engine.Always use a column list in your INSERT statements.This helps in avoiding problems when the table structure changes (like adding or dropping a column).Use sub query instead of a temporary table, unless strictly necessary.There are alternatives like the TABLE variable data type which can provide in-memory solutions for small tables inside stored procedures too.Avoid Wildcard SearchAvoid wildcards in search as much as possible.If not, then try to avoid wildcard characters at the beginning of a word while searching using the LIKE keyword.Example:Use this:SELECT LocationID FROM Locations WHERE Specialities LIKE 'A%s' Instead of this:SELECT LocationID FROM Locations WHERE Specialities LIKE'%pples'Use 'Derived tables' wherever possible, as they perform betterExample:Use this:SELECT MIN(Salary)FROM(SELECT TOP 2 SalaryFROM EmployeesORDER BY Salary DESC) AS AInstead of this:SELECT MIN(Salary)FROM EmployeesWHERE EmpID IN(SELECT TOP 2 EmpIDFROM EmployeesORDER BY Salary Desc)Prefix the tables, views and SP names with the owner's nameThis improves readability and avoids any unnecessary confusion.Qualifying table names with owner names helps in execution plan reuse, which further boosts performance.Lack of owner-qualification can introduce delays in stored procedure execution and unnecessarily high CPU utilization since it forces SQL to perform a second cachelookup and acquire an exclusive compile lock before determining that the existingcached execution plan can be reused.It is, however not necessary to qualify the stored proc with the database name to prevent the additional cache lookup.Use EXISTS clause instead of Count(*) for checking existenceUse EXISTS instead of COUNT(*) when looking for the existence of one or more rows in a subquery. EXISTS cancels the subquery once the first existence of a record isfound, while COUNT(*) forces processing of the entire query.Do not use column numbers in the ORDER BY clause.Consider the following example in which the first query is more readable than the second one:Example:Use thisSELECT OrderID, OrderDateFROM OrdersORDER BY OrderDateInstead of thisSELECT OrderID, OrderDateFROM OrdersORDER BY 2Use UNION ALL over UNION wherever possibleUse UNION ALL over UNION when the SELECT statement does not produce duplicate rows. UNION does an additional distinct operation over the accumulated result setwhich can be avoided in certain cases beforehandA UNION (without the ALL) performs an internal sorting to eliminate duplicate rows,thus creating a worktable hindering the performanceDo not use ORDER BY unless there is a requirementORDER BY uses resourcesTry to ORDER BY the indexed columns to improve performanceUse SQLCLR stored procedures, functions, triggers with careUse SQLCLR stored procedures only for computational intensive algorithmsAvoid calling a SQLCLR function for computations that can be performed in T-SQLAvoid using SQLCLR for set based computation. T-SQL is built for that and performs much fasterTry to avoid SQLCLR User defined aggregates if possible. It uses and disposes lots of objects in the aggregation process and might hit the performance during highconcurrencyCommon Table Expressions versus CROSS APPLY in hierarchy generation It is best to go for a Common Table Expressions if the joining columns of the self join are indexed.If index cannot be created to the joining columns then its better to use CROSS APPLY.CROSS APPLY does not use indexes. So it’s best to avoid this operator when indexes can be utilized in the query.CROSS APPLY is best suited if the number of rows returned is less and iteration depth < 5.Stored Procedures (SPs)Use Stored Procedures (SPs) wherever you can.Execution plans may be cached for improved performanceSeparate the business logic from presentation logicLimit multiple network calls by encapsulating complex business logicViewsDo not use indexed views unless you have one of the following scenarios:Joins and aggregations of large tablesRepeated patterns of queriesRepeated aggregations on the same or overlapping sets of columnsRepeated joins of the same tables on the same keysCombinations of the aboveThe query takes more than a few seconds to run. The index in the view is ignored unless SQL Server anticipates a real performance hitTransaction HandlingKeep transaction boundary short.Avoid nested transactions as much as possible.Do not use transactions inside stored procedures unless the stored procedure directly or indirectly executes more than one insert, update or delete statement.While using transactions inside stored procedures, name your transactions.Before exiting the stored procedure you must commit or rollback any transactions you began. Do not use implicit transactions ("SET IMPLICIT_TRANSACTIONS ON").CLR Integration guidelinesThe CLR stored procedures are efficient when the vector operations or complex mathematical operations are to be performed. For set based operations T-SQL is thebest.Avoid data access logic inside CLR procedures.When there is a need to use extended stored procedures, it is better to go for CLR procedures as an alternative.XML Usage GuidelinesUsage of OPENXMLStored procedures have the ability to accept XML and parse it into individual insert or update statements. This XML can contain many rows across many tables to affect in one document. This provides a significant performance increase because you only have the overhead of one network round trip for the entire commit rather than one round trip per modification to the database. However it is not the right choice for all kinds of applications. Some guidelines on the usage of OPENXML are given as follows:OPENXML is not recommended for online transactions with large number of concurrent users. This is typically recommended for batch processes where you mayneed to process and send large number of records for update into the database It is recommended to keep the size of the XML small and not process a huge XML document as this puts the SQL Server memory under pressure due to the recursivenature of processing the XML. Typical tests show that it is better to keep it under300K, but this number can vary based on the hardware and usage scenarios Bulk DML operations using OPENXML is not recommended if the requirement is to track individual rows for failure or successAttribute centric XML structure is preferred since the size is smallXML or Relational StorageFollow these guidelines when deciding the choice of storage (XML or relational)If your data is highly structured with known schema, then the relational model is likely to work best for data storage.XML is a good choice if you want a platform-independent model in order to ensure portability of the data by using structural and semantic markup. Additionally, it is anappropriate option if some of the following properties are satisfied:o Your data is sparse or you do not know the structure of the data, or the structure of your data may change significantly in the future.o Your data represents containment hierarchy, instead of references among entities, and may be recursive.o Order is inherent in your data.o You want to query into the data or update parts of it, based on its structure.ReferencesWebsitesCognizant Coding Standards / Guidelines can be accessed from the site:https://dotnet/Developercenter/Site%20Pages/Templates.aspx?RootFolder=%2fDevel opercenter%2fTemplatesGuidelines%2fDevelopment%20Guidelines&FolderCTID=&View=%7bBEA05050%2d5EEE%2d4896%2d97E5%2d6C3797634C8A%7dOthers URLs:/steven_bates/archive/2006/03/20/Database-Object-Naming-Rules.aspxSTUDENT NOTES:。