Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : mssql

mssqlÀïsp_MSforeachtableºÍsp_MSforeachdbµÄÓ÷¨

´Ómssql6.5¿ªÊ¼£¬Î¢ÈíÌṩÁËÁ½¸ö²»¹«¿ª£¬·Ç³£ÓÐÓõÄϵͳ´æ´¢¹ý³Ìsp_MSforeachtableºÍsp_MSforeachdb£¬ÓÃÓÚ±éÀúij¸öÊý¾Ý¿âµÄÿ¸ö±íºÍ±éÀúDBMS¹ÜÀíϵÄÿ¸öÊý¾Ý¿â¡£
ÎÒÃÇÔÚmasterÊý¾Ý¿âÀïÖ´ÐÐÏÂÃæµÄÓï¾ä¿ÉÒÔ¿´µ½Á½¸öprocÏêϸµÄ´úÂë
use master
exec sp_helptext sp_MSforeachtable
exec sp_helptext sp_Msforeachdb
sp_MSforeachtableϵͳ´æ´¢¹ý³ÌÓÐ7¸ö²ÎÊý£¬½âÊÍÈçÏ£º
@command1 nvarchar£¨2000£©, --µÚÒ»ÌõÔËÐеÄT-SQLÖ¸Áî
@replacechar nchar£¨1£© = N'?', --Ö¸¶¨µÄռλ·ûºÅ
@command2 nvarchar£¨2000£©= null,--µÚ¶þÌõÔËÐеÄT-SQLÖ¸Áî
@command3 nvarchar£¨2000£©= null, --µÚÈýÌõÔËÐеÄT-SQLÖ¸Áî
@whereand nvarchar£¨2000£©= null, --¿ÉÑ¡Ìõ¼þÀ´Ñ¡Ôñ±í
@precommand nvarchar£¨2000£©= null, --ÔÚ±íÇ°Ö´ÐеÄÖ¸Áî
@postcommand nvarchar£¨2000£©= null --ÔÚ±íºóÖ´ÐеÄÖ¸Áî
sp_MSforeachdb³ýÁË@whereandÍ⣬ºÍsp_MSforeachtableµÄ²ÎÊýÊÇÒ»ÑùµÄ¡£
--ÎÒÃÇÀ´¿´¿´sp_MSforeachtableµÄÓ÷¨£¨sp_MSforeachdbµÄÓ÷¨ÀàËÆ£©£º
--ͳ¼ÆÊý¾Ý¿âÀïÿ¸ö±íµÄÏêϸÇé¿ö£º
exec sp_MSforeachtable @command1="sp_spaceused '?'"
--¼ì²éÊý¾Ý¿âÀïÿ¸ö±í»òË÷ÒýÊÓͼµÄÊý¾Ý¡¢Ë÷Òý ......

²âÊÔMSSQLÖÐSQLÓï¾äÖ´Ðл¨·ÑµÄʱ¼ä

selectÓï¾äÇ°¼Ó£º
declare @d datetime
set @d=getdate()
²¢ÔÚselectÓï¾äºó¼Ó£º
select [Óï¾äÖ´Ðл¨·Ñʱ¼ä(ºÁÃë)]=datediff(ms,@d,getdate())
ת×Ô£º¶¯Ì¬ÍøÖÆ×÷Ö¸ÄÏ www.knowsky.com
ÕâÊǼòÒ׵IJ鿴ִÐÐʱ¼äµÄ·½·¨¡£
===========================================£¨Ò»ÏÂÄÚÈÝת×Ô£º£Ã£Ó£Ä£Î£©
MSSQL ServerÖÐͨ¹ý²é¿´SQLÓï¾äÖ´ÐÐËùÓõÄʱ¼ä£¬À´ºâÁ¿SQLÓï¾äµÄÐÔÄÜ¡£
set    statistics    profile    on
set    statistics    io    on
set    statistics    time    on
go
ÄãÖ´ÐеÄSQLÓï¾ä
go
set    statistics    profile    off
set    statistics    io    off
set    statistics    time    off
Ö´ÐÐÍêºóµãÏûÏ¢¼´¿É¡£
²¹³ä˵Ã÷£º
set    statistics    io ¼ì²é²éѯËù²úÉúµÄ¶ÁºÍд
set    statistics &nbs ......

²âÊÔMSSQLÖÐSQLÓï¾äÖ´Ðл¨·ÑµÄʱ¼ä

selectÓï¾äÇ°¼Ó£º
declare @d datetime
set @d=getdate()
²¢ÔÚselectÓï¾äºó¼Ó£º
select [Óï¾äÖ´Ðл¨·Ñʱ¼ä(ºÁÃë)]=datediff(ms,@d,getdate())
ת×Ô£º¶¯Ì¬ÍøÖÆ×÷Ö¸ÄÏ www.knowsky.com
ÕâÊǼòÒ׵IJ鿴ִÐÐʱ¼äµÄ·½·¨¡£
===========================================£¨Ò»ÏÂÄÚÈÝת×Ô£º£Ã£Ó£Ä£Î£©
MSSQL ServerÖÐͨ¹ý²é¿´SQLÓï¾äÖ´ÐÐËùÓõÄʱ¼ä£¬À´ºâÁ¿SQLÓï¾äµÄÐÔÄÜ¡£
set    statistics    profile    on
set    statistics    io    on
set    statistics    time    on
go
ÄãÖ´ÐеÄSQLÓï¾ä
go
set    statistics    profile    off
set    statistics    io    off
set    statistics    time    off
Ö´ÐÐÍêºóµãÏûÏ¢¼´¿É¡£
²¹³ä˵Ã÷£º
set    statistics    io ¼ì²é²éѯËù²úÉúµÄ¶ÁºÍд
set    statistics &nbs ......

MSSQLÊý¾Ý¿â±¸·Ý

1
¡¢
MSSQL
Êý¾Ý¿âµÄ¶¨ÆÚ×Ô¶¯±¸·Ý¼Æ»®
 
ͨ¹ýÆóÒµ¹ÜÀíÆ÷
ÉèÖÃÊý¾Ý¿âµÄ¶¨ÆÚ×Ô¶¯±¸·Ý¼Æ»®¡£
1
¡¢´ò¿ªÆóÒµ¹Ü
ÀíÆ÷£¬Ë«»÷´ò¿ªÄãµÄ·þÎñÆ÷
2
¡¢È»ºóµãÉÏÃæ
²Ëµ¥ÖеŤ¾ß
-->
Ñ¡ÔñÊý¾Ý¿âά»¤¼Æ»®Æ÷
3
¡¢ÏÂÒ»²½Ñ¡ÔñÒª½øÐÐ×Ô¶¯±¸·ÝµÄÊý¾Ý
-->
ÏÂÒ»²½¸üÐÂÊý¾ÝÓÅ»¯ÐÅÏ¢£¬ÕâÀïÒ»°ã²»ÓÃ×öÑ¡Ôñ
-->
ÏÂÒ»²½¼ì²éÊý¾ÝÍêÕûÐÔ£¬Ò²Ò»°ã²»Ñ¡Ôñ
4
¡¢ÏÂÒ»²½Ö¸¶¨Êý¾Ý¿âά»¤¼Æ»®£¬Ä¬ÈϵÄÊÇ
1
Öܱ¸·ÝÒ»´Î£¬µã»÷¸ü¸ÄÑ¡Ôñ±¸·ÝµÄÈÕÆÚ¼°Ê±¼äµã
È·¶¨
,
5
¡¢ÏÂÒ»²½Ö¸¶¨
±¸·ÝµÄ´ÅÅÌĿ¼£¬Ñ¡ÔñÖ¸¶¨Ä¿Â¼£¬È»ºóÑ¡Ôñɾ³ýÔçÓÚ¶àÉÙÌìÇ°µÄ±¸·Ý£¬Ñ¡ÔñÒ»¸öÐÇÆÚɾ³ýÒ»´Î±¸·Ý
,
¾ßÌ屸·Ý¿´ÄãµÄÒªÇ󣬱¸·ÝÎļþÀ©Õ¹ÃûĬÈϵÄÊÇ
BAK
6
¡¢ÏÂÒ»²½Ö¸¶¨ÊÂÎñÈÕÖ¾±¸·Ý¼Æ»®£¬¿´ÄãµÄÐèÒª×öÑ¡Ôñ
-->
ÏÂÒ»²½ÒªÉú³ÉµÄ±¨±í£¬Ò»°ã²»×öÑ¡Ôñ
-->
ÏÂÒ»²½Î¬»¤¼Æ»®ÀúÊ·¼Ç¼£¬×îºÃÓÃĬÈϵÄÑ¡Ïî
-->
ÏÂÒ»²½Íê³É
7
¡¢Íê³ÉºóϵͳºÜ¿ÉÄÜ»áÌáʾ
Sql
Server Agent
·þÎñδÆô¶¯£¬ÏȵãÈ·¶¨Íê³É¼Æ»®É趨£¬È»ºóÕÒµ½×ÀÃæ×îÓÒ±ß״̬À¸ÖеÄ
SQL
ÂÌɫͼ±ê£¬Ë«»÷µã¿ª£¬ÔÚ·þÎñÖÐÑ¡Ôñ
Sql
Server Agent
£¬È»ºóµã»÷ÔËÐмýÍ·£¬Ñ¡ÉÏÏ·½µÄµ±Æô¶¯
OS
ʱ×Ô¶¯Æô¶¯·þÎñ
8
¡¢¿ÉÒÔÉèÖÃÆô¶¯Æô¶ ......

½²½âMSSQLÊý¾Ý¿âÖÐSQLËø»úÖƺÍÊÂÎñ¸ôÀ뼶±ð

Ëø»úÖÆ
NOLOCKºÍREADPASTµÄÇø±ð¡£
1. ¿ªÆôÒ»¸öÊÂÎñÖ´ÐвåÈëÊý¾ÝµÄ²Ù×÷¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'a','a'
2. Ö´ÐÐÒ»Ìõ²éѯÓï¾ä¡£
SELECT * from Customer WITH (NOLOCK)
½á¹ûÖÐÏÔʾ"a"ºÍ"a"¡£µ±1ÖÐÊÂÎñ»Ø¹öºó£¬ÄÇôa½«³ÉΪÔàÊý¾Ý¡£(×¢:1ÖеÄÊÂÎñδÌá½») ¡£NOLOCK±íÃ÷ûÓжÔÊý¾Ý±íÌí¼Ó¹²ÏíËøÒÔ×èÖ¹ÆäËüÊÂÎñ¶ÔÊý¾Ý±íÊý¾ÝµÄÐ޸ġ£
SELECT * from Customer
ÕâÌõÓï¾ä½«Ò»Ö±ËÀËø£¬Ö±µ½ÅÅËûËø½â³ý»òÕßËø³¬Ê±ÎªÖ¹¡£(×¢:ÉèÖÃËø³¬Ê±SET LOCK_TIMEOUT 1800)
SELECT * from Customer WITH (READPAST)
ÕâÌõÓï¾ä½«ÏÔʾaδÌύǰµÄ״̬£¬µ«²»Ëø¶¨Õû¸ö±í¡£Õâ¸öÌáʾָÃ÷Êý¾Ý¿âÒýÇæ·µ»Ø½á¹ûʱºöÂÔ¼ÓËøµÄÐлòÊý¾ÝÒ³¡£
3. Ö´ÐÐÒ»Ìõ²åÈëÓï¾ä¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'b','b'
COMMIT TRAN t
Õâ¸öʱºò£¬¼´Ê¹²½Öè1µÄÊÂÎñ»Ø¹ö£¬ÄÇôaÕâÌõÊý¾Ý½«¶ªÊ§£¬¶øb¼ÌÐø²åÈëÊý¾Ý¿âÖС£
NOLOCK
1£® Ö´ÐÐÈçÏÂÓï¾ä¡£
BEGIN TRAN ttt
SELECT * from Customer WITH (NOLOCK)
WAITFOR delay '00:00:20'
COMMIT TRAN ttt
×¢£ºNOLOCK²»¼ÓÈκÎËø£¬¿ÉÒÔÔöɾ²é¸Ä¶ø²»Ëø¶¨¡£
INSERT INTO Customer SELECT 'a','b' –²»Ëø¶¨
......

½²½âMSSQLÊý¾Ý¿âÖÐSQLËø»úÖƺÍÊÂÎñ¸ôÀ뼶±ð

Ëø»úÖÆ
NOLOCKºÍREADPASTµÄÇø±ð¡£
1. ¿ªÆôÒ»¸öÊÂÎñÖ´ÐвåÈëÊý¾ÝµÄ²Ù×÷¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'a','a'
2. Ö´ÐÐÒ»Ìõ²éѯÓï¾ä¡£
SELECT * from Customer WITH (NOLOCK)
½á¹ûÖÐÏÔʾ"a"ºÍ"a"¡£µ±1ÖÐÊÂÎñ»Ø¹öºó£¬ÄÇôa½«³ÉΪÔàÊý¾Ý¡£(×¢:1ÖеÄÊÂÎñδÌá½») ¡£NOLOCK±íÃ÷ûÓжÔÊý¾Ý±íÌí¼Ó¹²ÏíËøÒÔ×èÖ¹ÆäËüÊÂÎñ¶ÔÊý¾Ý±íÊý¾ÝµÄÐ޸ġ£
SELECT * from Customer
ÕâÌõÓï¾ä½«Ò»Ö±ËÀËø£¬Ö±µ½ÅÅËûËø½â³ý»òÕßËø³¬Ê±ÎªÖ¹¡£(×¢:ÉèÖÃËø³¬Ê±SET LOCK_TIMEOUT 1800)
SELECT * from Customer WITH (READPAST)
ÕâÌõÓï¾ä½«ÏÔʾaδÌύǰµÄ״̬£¬µ«²»Ëø¶¨Õû¸ö±í¡£Õâ¸öÌáʾָÃ÷Êý¾Ý¿âÒýÇæ·µ»Ø½á¹ûʱºöÂÔ¼ÓËøµÄÐлòÊý¾ÝÒ³¡£
3. Ö´ÐÐÒ»Ìõ²åÈëÓï¾ä¡£
BEGIN TRAN t
INSERT INTO Customer
SELECT 'b','b'
COMMIT TRAN t
Õâ¸öʱºò£¬¼´Ê¹²½Öè1µÄÊÂÎñ»Ø¹ö£¬ÄÇôaÕâÌõÊý¾Ý½«¶ªÊ§£¬¶øb¼ÌÐø²åÈëÊý¾Ý¿âÖС£
NOLOCK
1£® Ö´ÐÐÈçÏÂÓï¾ä¡£
BEGIN TRAN ttt
SELECT * from Customer WITH (NOLOCK)
WAITFOR delay '00:00:20'
COMMIT TRAN ttt
×¢£ºNOLOCK²»¼ÓÈκÎËø£¬¿ÉÒÔÔöɾ²é¸Ä¶ø²»Ëø¶¨¡£
INSERT INTO Customer SELECT 'a','b' –²»Ëø¶¨
......

mssql Öн«ºº×Öת»»ÎªÆ´ÒôÊ××Öĸ·½·¨


1.
--½«ºº×Öת»»ÎªÆ´ÒôÊ××Öĸ
CREATE   function   GetAllPY(@str   nvarchar(4000))
returns   nvarchar(4000)
--WITH   ENCRYPTION
as
begin
declare   @intLen int
declare   @strRet nvarchar(4000)
declare   @temp   nvarchar(100)
set   @intLen   =   len(@str)
set   @strRet   =   ''
while   @intLen   >   0
begin
set   @temp   =   ''
select   @temp   =   case   
when   substring(@str,@intLen,1)   >=   '帀'   then   'Z'
when   substring(@str,@intLen,1)   >=   'Ѿ'   then   'Y'
when   substring(@str,@intLen,1)   >=   'Ϧ'   then   'X'
when   substring(@str,@intLen,1)   >=   '屲'   then   'W'
when   substring(@str,@intLen,1)   >=   'Ëû'   then   'T'
when   substring(@str,@intLen,1)   > ......

MSSQLÌí¼Ó×Ö¶Î˵Ã÷

--×Ö¶ÎÌí¼Ó˵Ã÷
EXEC sp_addextendedproperty 'MS_Description', 'ÒªÌí¼ÓµÄ˵Ã÷', 'user', dbo, 'table', ±íÃû, 'column', ÁÐÃû
--ɾ³ý×Ö¶Î˵Ã÷
EXEC sp_dropextendedproperty 'MS_Description', 'user', dbo, 'table', ±íÃû, 'column', ×Ö¶ÎÃû
--²é¿´×Ö¶Î˵Ã÷
SELECT
    [Table Name] = i_s.TABLE_NAME,
    [Column Name] = i_s.COLUMN_NAME,
    [Description] = s.value
from
    INFORMATION_SCHEMA.COLUMNS i_s
LEFT OUTER JOIN
    sysproperties s
ON
    s.id = OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME)
    AND s.smallid = i_s.ORDINAL_POSITION
    AND s.name = 'MS_Description'
WHERE
    OBJECTPROPERTY(OBJECT_ID(i_s.TABLE_SCHEMA+'.'+i_s.TABLE_NAME), 'IsMsShipped')=0
     AND i_s.TABLE_NAME = 'jobs'
ORDER BY
    i_s.TABLE_NAME, i_s.ORDINAL_POSITION ......
×ܼǼÊý:86; ×ÜÒ³Êý:15; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [1] [2] 3 [4] [5] [6] [7] [8] [9] [10]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ