Rebuild indexes online with SQL Server 2005
http://blogs.techrepublic.com.com/datacenter/?p=249
Online index rebuild
SQL Server 2005 introduces the ability to rebuild your indexes in an
online fashion so that other processes are able to access the table
while the rebuild is occurring. Because you can access the indexes
during the rebuild, you are not limited to only rebuilding indexes
during off-peak hours.
To accomplish this, the database engine takes some special actions
to rebuild the index and to allow access to the index at the same time.
The original index will remain available to users for reading data and
data modification. Row versioning is used to allow for transactional
consistency. During the rebuild, a new index is created that mimics the
old index. Any data modifications that alter the original index will
also be applied to this index by SQL Server during the rebuild. This
new index is not read from at all — it is write-only. It is essential
that you ......
SQL Server ¾Ñé £¨×ªÔØ£©
http://www.cnblogs.com/treeyh/archive/2007/08/06/844763.html
Èç¹ûÄãÕýÔÚ¸ºÔðÒ»¸ö»ùÓÚSQL ServerµÄÏîÄ¿£¬»òÕßÄã¸Õ¸Õ½Ó´¥SQL Server£¬Äã¶¼ÓпÉÄÜÒªÃæÁÙһЩÊý¾Ý¿âÐÔÄܵÄÎÊÌ⣬ÕâÆªÎÄÕ»áΪÄãÌṩһЩÓÐÓõÄÖ¸µ¼£¨ÆäÖдó¶àÊýÒ²¿ÉÒÔÓÃÓÚÆäËüµÄDBMS£©¡£
ÔÚÕâÀÎÒ²»´òËã½éÉÜʹÓÃSQL ServerµÄÇÏÃÅ£¬Ò²²»ÄÜÌṩһ¸ö°üÖΰٲ¡µÄ·½°¸£¬ÎÒËù×öµÄÊÇ×ܽáһЩ¾Ñé----¹ØÓÚÈçºÎÐγÉÒ»¸öºÃµÄÉè¼Æ¡£ÕâЩ¾ÑéÀ´×ÔÎÒ¹ýÈ¥¼¸ÄêÖоÊܵĽÌѵ£¬Ò»Ö±À´£¬ÎÒ¿´µ½Ðí¶àͬÑùµÄÉè¼Æ´íÎó±»Ò»´ÎÓÖÒ»´ÎµÄÖØ¸´¡£ ¡¡
Ò»¡¢Á˽âÄãÓõŤ¾ß ¡¡¡¡
²»ÒªÇá
ÊÓÕâÒ»µã£¬ÕâÊÇÎÒÔÚÕâÆªÎÄÕÂÖн²ÊöµÄ×î¹Ø¼üµÄÒ»Ìõ¡£Ò²ÐíÄãÒ²¿´µ½ÓкܶàµÄSQL Server³ÌÐòԱûÓÐÕÆÎÕÈ«²¿µÄT-SQLÃüÁîºÍSQL
ServerÌṩµÄÄÇЩÓÐÓõŤ¾ß¡£
¡¡¡¡“ʲô£¿ÎÒÒªÀË·ÑÒ»¸öÔµÄʱ¼äÀ´Ñ§Ï°ÄÇЩÎÒÓÀÔ¶Ò²²»»áÓõ½µÄSQLÃüÁ£¿£¿”£¬ÄãÒ²Ðí»áÕâÑù˵¡£¶ÔµÄ£¬Äã²»ÐèÒªÕâÑù×ö¡£µ«ÊÇÄãÓ¦¸ÃÓÃÒ»¸öÖÜÄ©ä¯ÀÀËù
ÓеÄT-SQLÃüÁî¡£ÔÚÕâÀÄãµÄÈÎÎñÊÇÁ˽⣬½«À´£¬µ±ÄãÉè¼ÆÒ»¸ö²éѯʱ£¬Äã»á¼ÇÆðÀ´£º“¶ÔÁË£¬ÕâÀïÓÐÒ»¸öÃüÁî¿ÉÒÔÍêȫʵÏÖÎÒÐèÒªµÄ¹¦ÄÜ”£¬ÓÚÊÇ£¬µ½
MSDN²é¿ ......
[Sql]EXCEPT ºÍ INTERSECT¹Ø¼ü×Ö
http://www.cnblogs.com/treeyh/archive/2008/07/01/1232845.html
EXCEPT
´Ó EXCEPT ²Ù×÷Êý×ó±ßµÄ²éѯÖзµ»ØÓұߵIJéѯδ·µ»ØµÄËùÓзÇÖØ¸´Öµ¡£
INTERSECT
·µ»Ø INTERSECT ²Ù×÷Êý×óÓÒÁ½±ßµÄÁ½¸ö²éѯ¾ù·µ»ØµÄËùÓзÇÖØ¸´Öµ¡£
A. ʹÓà EXCEPT
ÔÚʾÀýÖÐʹÓà TableA ºÍ TableB ÖеÄÊý¾Ý¡£
TableA (col1 int)
TableB (col1 int)
NULL
NULL
NULL
1
NULL
3
1
4
2
4
2
2
3
4
4
ÒÔϲéѯ´Ó EXCEPT
²Ù×÷Êý×ó²àµÄ²éѯ·µ»ØÓÒ²à²éѯûÓÐÕÒµ½µÄËùÓзÇÖØ¸´Öµ¡£
SELECT * from TableA EXCEPT
SELECT * from TableB;
ÏÂÃæÊǽá¹û¼¯£º
Col1
-----------
2
(1 row(s) affected)
B. ʹÓà INTERSECT
ÔÚʾÀýÖÐʹÓà TableA ºÍ TableB ÖеÄÊý¾Ý¡£
TableA (col1 int)
TableB (col1 int)
NULL
2
NULL
2
NULL
2
1
4
2
4
2
2
3
4
4
ÒÔϲéѯ·µ»Ø INTERSECT
²Ù×÷Êý×óÓÒÁ½²àµÄÁ½¸ö²éѯ¾ù·µ»ØµÄËùÓзÇÖØ¸´Öµ¡£
SELECT * from TableA INTERSECT ......
1£ºSQL ServerÊý¾Ý¿âÅäÖÃ
¿ªÆô·þÎñÆ÷
ÍÐÅÌÏÔʾ·þÎñÆ÷Æô¶¯
2:ÔÚStaAfx.h ÖÐÌí¼ÓÈçÏ´úÂë
#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")rename("BOF","adoBOF")
//³öÏÖmsado15.dll ±íʾµ¼Èë³É¹¦
3:ÔÚBOOL CXXXApp::InitInstance()Öгõʼ»¯COM»·¾³
BOOL CXXXApp::InitInstance()
{
AfxEnableControlContainer();
::CoInitialize(NULL);
…….
ÊÍ·ÅCOM»·¾³
::CoUninitialize();
return FALSE;
}
4£ºËµÃ÷
ÀûÓÃϵͳĬÈ϶¨ÒåÈ«¾ÖCXXXAppÀàµÄ¶ÔÏótheApp¿ÉÒÔµ÷ÓÃÀà·½·¨£¨º¯Êý£©µÄÄÜÁ¦£¬
¹ÊÔÚCXXXAppÀàÖмÓÈëÁ¬½ÓÊý¾Ý¿âµÄ¹«¹²·½·¨—InitADOConn£¨£©ºÍ¹«¹²Êý¾Ý—
&nb ......
1£ºSQL ServerÊý¾Ý¿âÅäÖÃ
¿ªÆô·þÎñÆ÷
ÍÐÅÌÏÔʾ·þÎñÆ÷Æô¶¯
2:ÔÚStaAfx.h ÖÐÌí¼ÓÈçÏ´úÂë
#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF","adoEOF")rename("BOF","adoBOF")
//³öÏÖmsado15.dll ±íʾµ¼Èë³É¹¦
3:ÔÚBOOL CXXXApp::InitInstance()Öгõʼ»¯COM»·¾³
BOOL CXXXApp::InitInstance()
{
AfxEnableControlContainer();
::CoInitialize(NULL);
…….
ÊÍ·ÅCOM»·¾³
::CoUninitialize();
return FALSE;
}
4£ºËµÃ÷
ÀûÓÃϵͳĬÈ϶¨ÒåÈ«¾ÖCXXXAppÀàµÄ¶ÔÏótheApp¿ÉÒÔµ÷ÓÃÀà·½·¨£¨º¯Êý£©µÄÄÜÁ¦£¬
¹ÊÔÚCXXXAppÀàÖмÓÈëÁ¬½ÓÊý¾Ý¿âµÄ¹«¹²·½·¨—InitADOConn£¨£©ºÍ¹«¹²Êý¾Ý—
&nb ......
SQL:Structured Query Language,1974ÄêBoyceºÍChamberlinÌá³ö.
Êý¾Ý¶¨Òå :CREATE,DROP
Êý¾Ý¿â²éѯ:SELECT
Êý¾Ý²Ù×Ý :INSERT,UPDATE,DELETE
Êý¾Ý¿ØÖÆ :GRANT,REVOKE
Ò».Êý¾ÝµÄ¶¨ÒåºÍÐÞ¸Ä:
1.¶¨Òå»ù±í
CREATE TABLE ±íÃû (<ÁÐÃû1 ÀàÐÍ[NOT NULL][,ÁÐÃû2 ÀàÐÍ[NOT NULL]>…[ÆäËû²ÎÊý]);
¹ØÓÚÀàÐÍ:
INTEGER È«×Ö³¤µÄ¶þ½øÖÆÕûÊý.
SMALLINT °ë×Ö³¤µÄ¶þ½øÖÆÕûÊý.
DECIMAL(p[,q])ѹËõÊ®½øÖÆÊý,¹²pλСÊýµãºóÓÐqλ,15>=p>=q>=0,q=0ʱ¿ÉÊ¡ÂÔ.
FLOAT Ë«×Ö³¤µÄ¸¡µãÊý.
CHAR(n) ³¤¶ÈΪnµÄ¶¨³¤×Ö·û´®.
VARCHAR(n)±ä³¤×Ö·û´®,×î´ó³¤Îªn.
2.Ð޸Ļù±í
ALTER TABLE ±íÃû ADD ÁÐÃû ÀàÐÍ; //Ôö¼ÓÐÂÁÐ.
3.ɾ³ý»ù±í
DROP TABLE ±íÃû; //ɾ³ý»ù±íÁ¬Í¬±íÖмǼ.
¶þ.ÊÓͼµÄ¶¨Òå
1.¶¨ÒåÊÓͼ
CREATE VIEW ÊÓͼÃû[ÁÐÃû[,ÁÐÃû]…]AS ×Ó²éѯ[WITH CHECK OPTION];
2.ÊÓͼɾ³ý
DROP VIEW ÊÓͼÃû;
Èý.Êý¾Ý²Ù×Ý
SELECT [DISTINCT] Ñ¡ÔñÊä³öÊôÐÔ±í
from Òª¼ìË÷µÄ±íÃû
[WHERE ¼ìË÷Ó¦Âú×ãµÄÌõ¼þ]
[GROUP BY ·Ö×éÊôÐÔ±í(HAVING ¼ìË÷Ìõ¼þ)]
[ORDER BY ÅÅÐòÊôÐÔ±í];
1. ¼òµ¥²éѯ
(1).²»Ïû³ýÖØ¸´Ôª×éµÄ¼ìË÷
SELECT TITLE from BOOKS
(2).Ïû³ýÖØ¸´Ôª×éµÄ¼ìË ......
http://www.sql-server-performance.com/tips/clustered_indexes_p1.aspx
As a rule of thumb, every table should have a clustered index. Generally, but not always, the clustered index should be on a column that monotonically increases--such as an identity column, or some other column where the value is increasing--and is unique. In many cases, the primary key is the ideal column for a clustered index.
If you have any experience with performance tuning SQL Server 6.5, you may have heard that is not a good idea to add a clustered index to a column that monotonically increases because it can cause a "hotspot" on the disk that can cause performance problems. That advice is true in SQL Server 6.5.
Normally, "hotspots" aren't generally a problem. You would have to have over 1,000 transactions a second before a "hotspot" were to negatively affect performance. In fact, a "hotspot" can be beneficial under these circumstances because it eliminates page spli ......