Create database sample
The primary filegroup with the files Spri1_dat and Spri2_dat. The FILEGROWTH increment for both of these files is specified as 15 percent. A filegroup named SalesGroup1 with the files SGrp1Fi1 and SGrp1Fi2. A filegroup named SalesGroup2 with the files SGrp2Fi1 and SGrp2Fi2.CREATE DATABASE SalesON PRIMARY( NAME = SPri1_dat,FILENAME = 'c:program filesmicrosoft sql servermssql.1mssqldataSPri1dat.mdf',SIZE = 10,MAXSIZE = 50,FILEGROWTH = 15% ),( NAME = SPri2_dat,FILENAME = 'c:prog
The Curse and Blessings of Dynamic SQL
If you follow the various newsgroups on Microsoft SQL Server, you often see people asking why they can't do: SELECT * FROM @tablenameSELECT @colname FROM tblSELECT * FROM tbl WHERE x IN (@list) For all three examples you can expect someone to answer Use dynamic SQL and give a quick example on how to do it. Unfortunately, for all three examples above, dynamic SQL is a poor solution. On the other hand, there are situations where dynamic SQL is the best or only way to go. In t
日记传送
日志传送(log shipping)主要基于SQL Server代理,使用定时作业来完成,另外在配置日志传送之前必须要创建共享文件夹,用于辅助服务器访问。这里我们假设有数据库logTrans1需要 进行日志传送,共享文件夹为“C:data”,在T-SQL中配置日志传送主要有以下几步操作: (1)备份主数据库并在辅助服务器上还原主数据库的完整备份,初始化辅助数据库。具体操作如代码: backup database logTrans1 --在主数据库上备份 to disk='c:logt.bak' --以下是将数据库还原到辅助数据库上 restore database logTrans2 from disk='c:logt.bak'
Transact-SQL Query Performance Tuning Tips
In this article, I will discuss some T-SQL query performance tips and tricks for SQL server programmers. The tips mentioned in this article may sound obvious to most of you, but I have seen professional developers who don't think before using them.My first tip is not using a WHERE clause in your SELECT statement to narrow the number of rows returned. If you don't use a WHERE clause, then SQL Server will perform a table scan of your table and return all of the rows. In some case you may w
Generate a list of dates
select dp.NAME AS principal_name, dp.type_desc AS principal_type_desc, o.NAME AS object_name, p.permission_name, p.state_desc AS permission_state_desc from sys.database_permissions p left OUTER JOIN sys.all_objects o on p.major_id = o.OBJECT_ID inner JOIN sys.database_principals dp on p.grantee_principal_id = dp.principal_id with mycte as ( select cast('1900-01-01' as datetime) DateValue union a
SQL Server Error Handling Workbench
Normal 0 7.8 pt 0 2 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-or
Database coding conventions
Normal 0 7.8 pt 0 2 false false false MicrosoftInternetExplorer4 st1:*{behavior:url(#ieooui) } /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bott