
SQL Basic Knowledge
文章平均质量分 58
envykok
这个作者很懒,什么都没留下…
展开
-
How do I search for special characters (e.g. %) in SQL Server?
http://sqlserver2000.databases.aspfaq.com/how-do-i-search-for-special-characters-e-g-in-sql-server.html<br />There are several characters that have special meaning within aSQL query, for example the percent sign (%) in a LIKE query is awildcard that es转载 2010-09-07 15:55:00 · 214 阅读 · 0 评论 -
Explanation for Sys.dm_db_missing_index_group_stats DMV return columns
<br /> <br />http://sqlserverpedia.com/wiki/DM_Objects_-_Sys.dm_db_missing_index_group_stats<br /> <br />Sys.dm_db_missing_index_group_stats DMV returns statistical informationabout estimated improvement each missing index could provide onceimplemented转载 2010-09-09 10:31:00 · 188 阅读 · 0 评论 -
SQL SERVER – Four Different Ways to Find Recovery Model for Database
<br />http://blog.sqlauthority.com/2009/07/16/sql-server-four-different-ways-to-find-recovery-model-for-database/<br /> <br />Perhaps, the best thing about technicaldomain is that most of the things can be executed in more than oneways. It is always us转载 2010-09-09 02:09:00 · 158 阅读 · 0 评论 -
Block IP Addresses to SQL Server using a Logon Trigger
<br />http://www.sqlservercurry.com/2010/09/block-ip-addresses-to-sql-server-using.html<br /> <br />We were testing a scenario and wanted to block SQLServer connection through certain IP addresses. Here’s how we solvedthe requirement using a Logon Trig转载 2010-09-16 18:40:00 · 180 阅读 · 0 评论 -
SQL SERVER – QUOTED_IDENTIFIER ON/OFF and ANSI_NULL ON/OFF Explanation
<br />http://blog.sqlauthority.com/2007/03/05/sql-server-quoted_identifier-onoff-and-ansi_null-onoff-explanation/<br />When create or alter SQL object likeStored Procedure, User Defined Function in Query Analyzer, it iscreated with following SQL comman转载 2010-09-17 14:22:00 · 172 阅读 · 0 评论 -
SQL SERVER – 2008 – Introduction to Policy Management – Enforcing Rules on SQL Server
http://blog.sqlauthority.com/2008/06/13/sql-server-2008-introduction-to-policy-management-enforcing-rules-on-sql-server/Ihave previous written article about SQL SERVER Database Coding Standards and Guidelines Complete List Download.I just received ques转载 2010-09-17 01:26:00 · 182 阅读 · 0 评论 -
概念 OLTP vs. OLAP
<br />http://datawarehouse4u.info/OLTP-vs-OLAP.html<br /><br />- OLTP (On-line Transaction Processing) is characterized by a large number of short on-line transactions (INSERT, UPDATE, DELETE). The main emphasis for OLTP systems is put on very fast q转载 2010-09-07 22:59:00 · 163 阅读 · 0 评论 -
SQL SERVER – Three T-SQL Script to Create Primary Keys on Table
<br />http://blog.sqlauthority.com/2007/10/16/sql-server-three-t-sql-script-to-create-primary-keys-on-table/<br /> <br />I have always enjoyed writing about three topics Constraint and Keys, Backup and Restore and Datetime Functions.<br />Primary Keys co转载 2010-09-17 12:51:00 · 176 阅读 · 0 评论 -
Using SSMS to change the Edit TOP Rows option
<br />http://www.sqlservercurry.com/2009/09/using-ssms-to-change-edit-top-rows.html<br /> <br />SQL Server 2008 Management Studio has an option to Edit the Top 200Rows. Just Right Click on the Table and you get the following options:<br /><br />Ifyour转载 2010-09-16 19:08:00 · 161 阅读 · 0 评论 -
SQL Server 2005高可用性之镜像功能
<br />http://tech.it168.com/db/s/2007-04-24/200704240837593.shtml<br /> <br />【IT168 技术开发】SQL Server 2005相对于SQL Server2000来说,无论是性能还是功能都有一个相当大的提高,甚至可以用“革命”来形容这一次升级。SQL Server 2005使 SQLServer 跻身于企业级数据库行列。在数据高可用性方面,SQL Server2005为用户提供了数据镜像、复制、故障转移群集、日转载 2010-09-16 15:56:00 · 179 阅读 · 0 评论 -
SQL Server Bulk-Logged Recovery Model
SQL Server Bulk-Logged Recovery Model<br />(SET RECOVERY BULK_LOGGED) <br /> <br />http://www.mssqltips.com/tutorial.asp?tutorial=5<br />Overview<br />The"Bulk-logged" recovery model sort of does what it implies. With this转载 2010-09-01 11:44:00 · 318 阅读 · 0 评论 -
Why we need refresh view after change table
<br />http://www.mssqltips.com/tip.asp?tip=1427<br /> <br />Problem<br />I recently added a column to one of my coresystem tables referenced by a reporting view. When I run the view, theadded column is not appearing in my result set! What can I do?<b转载 2010-10-08 17:36:00 · 367 阅读 · 0 评论 -
Changing the name of your SQL server
<br />http://www.zdnetasia.com/changing-the-name-of-your-sql-server-62045446.htm<br />Have you ever had to change the name of a server that has SQL Serverinstalled on it? If you anwered yes, did you know that you also have tochange the name in SQL Serv转载 2010-10-19 19:01:00 · 173 阅读 · 0 评论 -
SQL And Statistics
/****** Object: Index [LISTINGFEED_ID_LISTING_IDUN] Script Date: 12/10/2010 22:22:40 ******/statisticehelping the optimizercost base - sys.stats - DBCC SHOW_STATISTICS(table_name,statsname)auto-generate statistics will be single原创 2010-12-12 22:55:00 · 150 阅读 · 0 评论 -
Auditing in SQL Server 2005&2008
<br /><br />Audits on MS SQL Server 2008<br />http://www.sql-server-performance.com/articles/audit/2008_audit_intro_p1.aspx<br />**The Audit feature is supported only in Enterprise and Developer editions of SQL Server 2008<br /> <br />Introduction to Chang原创 2011-04-25 18:26:00 · 225 阅读 · 0 评论 -
sql语句中获取datetime的日期部分或时间部分
<br />要方法还是通过日期格式的转换来获取。如下:<br /><br />Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM<br />Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06<br />Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16<br />Select CONVERT(varchar(10转载 2010-11-21 17:06:00 · 233 阅读 · 0 评论 -
SQL SERVER – 2005 – OUTPUT Clause Example and Explanation with INSERT, UPDATE, DELETE
<br />http://blog.sqlauthority.com/2007/10/01/sql-server-2005-output-clause-example-and-explanation-with-insert-update-delete/<br /> <br />SQL Server 2005 has new OUTPUT clause, which is quite useful. OUTPUT clause has accesses to inserted and deleted tabl转载 2010-10-29 00:47:00 · 193 阅读 · 0 评论 -
Order of tigger, constraint and user query
'...If constraints exist on the trigger table, they are checked after theINSTEAD OF trigger execution and before the AFTER trigger execution.'( comes form http://msdn.microsoft.com/en-us/library/ms189799.aspx)'...AFTER AFTER specifies that the DML trigge原创 2010-10-24 23:09:00 · 168 阅读 · 0 评论 -
SET IDENTITY_INSERT
<br />http://blog.youkuaiyun.com/luzhuxi/archive/2009/03/26/4027065.aspx<br />想要将值插入到自动编号(或者说是标识列,IDENTITY)中去,需要设定 SET IDENTITY_INSERT<br />示例:<br />1.首先建立一个有标识列的表:<br />CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))<br />2.尝试在表中做以下操作转载 2010-09-01 14:00:00 · 176 阅读 · 0 评论 -
SqlServer 2005 设置字段/表 的描述字段
<br /> <br /> <br />refer to http://hi.baidu.com/cp899/blog/item/96c17709c1571d980b7b8244.html<br /> SQL Server 2000提供了三个系统存储过程和一个函数用于操作扩展属性。它们分别是:sp_addextendedproperty(将新扩展属性添加到数据库对象中。)sp_updateextendedproperty(更新现有扩展属性的值。)sp_dropextendedproperty转载 2010-06-24 11:05:00 · 291 阅读 · 0 评论 -
SQL Server Recovery Models
<br />http://databases.about.com/od/sqlserver/a/recoverymodels.htm<br />SQL Server provides three different recovery models that allow you to specify the way SQL Server manages log files and prepares your enterprise for a disaster. Each of these models rep转载 2010-06-15 23:55:00 · 390 阅读 · 0 评论 -
[Sql]EXCEPT 和 INTERSECT关键字
[Sql]EXCEPT 和 INTERSECT关键字http://www.cnblogs.com/treeyh/archive/2008/07/01/1232845.htmlEXCEPT从 EXCEPT 操作数左边的查询中返回右边的查询未返回的所有非重复值。INTERSECT返回 INTERSECT 操作数左右两边的两个查询均返回的所有非重复转载 2010-05-30 19:01:00 · 197 阅读 · 0 评论 -
table and store procedure create date and modify date
<br /> <br /> <br />This post demonstrates the script which displays create date and modify date for any specific stored procedure in SQL Server.<br />USE AdventureWorks;<br />GO<br />SELECT name, create_date, modify_date<br />FROM sys.objects<br />WHE转载 2010-05-31 11:04:00 · 186 阅读 · 0 评论 -
SQL SERVER – Stored Procedure to display code (text) of Stored Procedure, Trigger, View or Object
SQL SERVER – Stored Procedure to display code (text) of Stored Procedure, Trigger, View or Objecthttp://blog.sqlauthority.com/2007/05/25/sql-server-stored-procedure-to-display-code-text-of-stored-转载 2010-05-27 00:06:00 · 190 阅读 · 0 评论 -
字符串和子字符串的问题
已知字符,求字符串位置 SELECT charindex(est, testing) -----------2(1 row(s) affected) 已知字符位置,求字符串 SELECT SUBSTRING(testing,1,3) ----tes(1 row(s) affected)原创 2010-05-25 14:12:00 · 179 阅读 · 0 评论 -
SQL 随机数
SQL 随机数 select floor(rand()*100); --求随机数据 Solution 1 : SELECT TOP 1 * FROM [tablename] ORDER BY NEWID() Solution 2 :Declare @ID INTSELECT @ID=floor(rand()*100) SELECT TOP原创 2010-05-25 00:14:00 · 185 阅读 · 0 评论 -
sp_who/sp_who2
sp_who/sp_who2 [ [ @loginame = ] login | session ID | ACTIVE ]sp_who returns a result set with the following information. Column Da原创 2010-05-24 23:51:00 · 431 阅读 · 0 评论 -
SQL replication
<br />(1) 在SQL SERVER Instance A 创建publish (源)<br /> <br /><br /> <br /><br /> <br /> <br />(2) 在SQL SERVER Instance B 创建subscriber(目标)<br /> <br /><br /> <br />原创 2010-07-19 00:54:00 · 144 阅读 · 0 评论 -
SQL SERVER – Difference Between Unique Index vs Unique Constraint
http://blog.sqlauthority.com/2007/04/26/sql-server-difference-between-unique-index-vs-unique-constraint/ Unique Index and Unique Constraint are the same. They achieve same goal. SQL Performance is转载 2010-05-24 11:47:00 · 184 阅读 · 0 评论 -
sp_lock显示的信息说明
sp_lock显示的信息说明 From:http://www.cnblogs.com/phantomfox/archive/2006/12/11/588994.html***************************************************************************管理员可以使用系统存储过程来方便地查看当前对象上锁转载 2010-05-25 00:01:00 · 213 阅读 · 0 评论 -
SQL Linked Server
http://topic.youkuaiyun.com/u/20080612/22/bb2dfa83-1cf3-4a0b-9bd4-5a39e6193556.html--遠程連接操作/******************************************************************************************************************************************************Tab表:/*ID 自增转载 2010-07-02 11:55:00 · 243 阅读 · 0 评论 -
sqlserver中的自定义聚合函数
--测试表create table Test(F1 varchar(10), F2 varchar(10))--插入数据insert into Test select 'jack' F1,'book1' F2unionselect 'jack' F1,'book2' F2unionselect 'jack' F1,'book3' F2unionselect 'Mary' F1,'book4' F2unionselect 'Mary' F1,'book5' F2unionselect 'Mike' F转载 2010-06-30 01:02:00 · 490 阅读 · 0 评论 -
基础概念
http://www.ixpub.net/archiver/tid-842760.html4、什么叫做bookmark lookup?潜在的会有什么缺点?通过non clustered index上的rowno找数据页的过程就叫bookmark lookup。如果一次查的数据太多,超过表的3分之1就还不如全表扫描12、某些sql执行后,在消息中,会发现有worktable,I/O很大,解释此现象。sql要排序,group by,union的时候会用到worktable,如果数据量很大转载 2010-05-31 23:49:00 · 130 阅读 · 0 评论 -
Get Database Create by Who and When in SQL SERVER
USE [master] <br />GO<br /><br />select l.name AS created_by ,d.name,d.create_date from sys.databases d <br />inner join sys.syslogins l on d.owner_sid=l.sid <br />where d.name='dbname'<br /><br /><br />原创 2010-07-27 12:39:00 · 138 阅读 · 0 评论 -
Recompiling Stored Procedure
Recompiling Stored Procedure <br />http://www.dotnetspider.com/resources/28544-Recompiling-Stored-Procedure.aspx<br /><br />Recompilinga stored procedure is necessary when the stored procedure changes everytime of calling. By the normal way of stor转载 2010-07-29 12:23:00 · 197 阅读 · 0 评论 -
Update query with inner join
<br /><br />Sample:<br /><br />UPDATE AliasA<br />SET CarMaker = mstMakerModel.Maker<br />FROM tblCarAuctionList AS AliasA INNERJOIN<br /> mstMakerModel ON AliasA.CarName = mstMakerModel.Model <br />原创 2010-08-10 00:11:00 · 160 阅读 · 0 评论 -
Rename table & index in SQL 2008
<br />sp_rename 'tablename','new table name'<br /> <br />sp_rename 'table.index','new index name','INDEX'原创 2010-08-02 16:42:00 · 165 阅读 · 0 评论 -
SQLServer2005的Top功能
<br /> http://blog.youkuaiyun.com/jinjazz/archive/2009/09/04/4520749.aspx<br /> <br />所有人都知道select top 的用法,但很多人还不知道update top 和 delete top 怎么用。以往的做法是setrowcount来指定,其实SQL2005中对于Top语句的增强除了参数化之外还包括对update和delete的支持,但可惜的是还不支持自定义的order by列。如果要自定义派序列可以借助CTE.对于CTE的转载 2010-06-07 15:45:00 · 154 阅读 · 0 评论 -
Update Top N rows in sql server 2005
<br />-- USING TOP(N) WITH UPDATE OPERATION<br />UPDATE TOP(10) tablename SET NAMES='AAAAAA'原创 2010-06-07 15:23:00 · 156 阅读 · 0 评论 -
查询SQL Server数据库表占用空间大小的代码
<br />下面来介绍一下两种用来方法。<br /><br />http://www.zhangyongjun.com/blog/article.asp?id=4618<br /> <br /> <br />方法1:<br /> select object_name(id) tablename,8*reserved/1024 reserved,rtrim(8*dpages/1024)+'Mb' used,8*(reserved-dpages)/1024 unused,8*dpages/1024-r转载 2010-06-07 14:00:00 · 262 阅读 · 0 评论