Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL SERVERÐÔÄÜ·ÖÎö ËÀËø¼ì²âÊý¾Ý¿â×èÈûÓï¾ä

×÷ÖÐÊý¾Ý¿â¾­³£³ö´íËÀËø£¬²¢ÇÒ»¹ÒªÒªÇó½â¾öµ±Ç°µÄËÀËø£¬ÎÊÌâ¶à¶à£»
²ÎÕÕCSDN£¬Öйú·ç(Roy)һƪËÀËøÎÄÕ²¢¸Ä½øÁËÏ£»
/***********************************************************************************************************************
ÕûÀíÈË£ººÚľÑÂÉϵÄÎÏÅ£(lenolotus) ÈÕÆÚ:2009.04.28
************************************************************************************************************************/
/***********************************************************************************************************************
×èÈû£ºÆäÖÐÒ»¸öÊÂÎñ×èÈû£¬ÆäËüÊÂÎñµÈ´ý¶Ô·½ÊÍ·ÅËüÃǵÄËø,ͬʱ»áµ¼ÖÂËÀËøÎÊÌâ¡£ ÕûÀíÈË£ºÖйú·ç(Roy) ²ÎÕÕRoy_88µÄ²©¿Í
http://blog.csdn.net/roy_88/archive/2008/07/21/2682044.aspx
ÈÕÆÚ:2008.07.20
************************************************************************************************************************/
--Éú³É²âÊÔ±íTa
if not object_id('Ta') is null
drop table Ta
go
create table Ta(ID int Primary key,Col1 int,Col2 nvarchar(10))
insert Ta
select 1,101,'A' union all
select 2,102,'B' union all
select 3,103,'C'
go
Éú³ÉÊý¾Ý:
/*
±íTa
ID Col1 Col2
----------- ----------- ----------
1 101 A
2 102 B
3 103 C (3 ÐÐÊÜÓ°Ïì) */
1¡¢½«´¦Àí×èÈû¼õµ½×îÉÙ:
2¡¢²»ÒªÔÚÊÂÎñÖÐÇëÇóÓû§ÊäÈë
3¡¢ÔÚ¶ÁÊý¾Ý¿¼ÂDZãÓÃÐа汾¹ÜÀí
4¡¢ÔÚÊÂÎñÖо¡Á¿·ÃÎÊ×îÉÙÁ¿µÄÊý¾Ý
5¡¢¾¡¿ÉÄܵØʹÓõ͵ÄÊÂÎñ¸ôÀ뼶±ð
×èÈû1(ÊÂÎñ):
--²âÊÔµ¥±í
-----------------------Á¬½Ó´°¿Ú1(update\insert\delete)------------------------------
begin tran
--update
update ta set col2='BB' where ID=2
--»òinsert
--begin tran
-- insert Ta values(4,104,'D')
--»òdelete
--begin tran
-- delete ta where ID=1
--rollback tran
-------------------------Á¬½Ó´°¿Ú2£¨²éѯ±í£©---------------------------------------------
begin tran
select * from ta
--rollback tran
--- --·ÖÎö--------------------------------------------------
-->SQL SERVER 2005²éѯËÀËø½ø³Ì
select
request_session_id as spid,
resource_type,
db_name(resource_database_id) as dbName


Ïà¹ØÎĵµ£º

SQL ɾ³ýÖظ´Êý¾Ý£¬Ö»±£Áô1Ìõ

if not object_id('Tempdb..#T') is null
    drop table #T
Go
Create table #T([ID] int,[Name] nvarchar(1),[Memo] nvarchar(2))
Insert #T
select 1,N'A',N'A1' union all
select 2,N'A',N'A2' union all
select 3,N'A',N'A3' union all
select 4,N'B',N'B1' union all
select 5,N'B',N'B2'
G ......

SQL ÕÒ³ö¶à¸ö×Ö¶ÎÂú×ãÆäÖÐÒ»¸ö×ֶεÄÐÂд·¨

ÕÒ³öTABLE1ÖÐ
Column1 Âú×ãvalue1
»òÕß
Column2 Âú×ãvalue2
»òÕß
Column3 Âú×ãvalue3
µÄ¼Í¼
SELECT top 10 * from TABLE1
WHERE
CASE WHEN COLUMN1='value1' THEN 1
ELSE
(CASE WHEN COLUMN2='value2' THEN 1
ELSE
(CASE WHEN COLUMN3=value3 THEN 1 ELSE 0 END)
END)
END =1 ......

SQL ΪÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±íÖÐͬʱ²åÈë¶àÌõÊý¾Ý

ÓÐʱÎÒÃÇ»áÏñÏÂÃæµÄÇé¿öÒ»Ñù£¬ÎªÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±í(T_Stud_Course ±í)ÖÐͬʱ²åÈë¶àÌõÊý¾Ý
T_Student ±í
Stud_ID
Name
1
Tom
2
Jack
T_Course ±í
Course_ID
Course
1
Chinese
2
English
T_Stud_Course ±í
ID
Stud_ID
Course_ID
1
1
1
2
1
2
3
2
2
 
ÏÖÔÚÎÒÃÇ¿ÉÒÔÏÂÃæµÄ´æ´¢¹ý³ÌÀ ......

SQL ServerË÷ÒýÔ­Ôò

ÈçºÎÈÃÄãµÄSQLÔËÐеøü¿ì
---- ÈËÃÇÔÚʹÓÃSQLʱÍùÍù»áÏÝÈëÒ»¸öÎóÇø£¬¼´Ì«¹Ø×¢ÓÚËùµÃµÄ½á¹ûÊÇ·ñÕýÈ·£¬¶øºöÂÔÁ˲»Í¬µÄʵÏÖ·½·¨Ö®¼ä¿ÉÄÜ´æÔÚµÄÐÔÄܲîÒ죬ÕâÖÖÐÔÄܲîÒìÔÚ´óÐ͵ĻòÊǸ´ÔÓµÄÊý¾Ý¿â»·¾³ÖУ¨ÈçÁª»úÊÂÎñ´¦ÀíOLTP»ò¾ö²ßÖ§³ÖϵͳDSS£©ÖбíÏÖµÃÓÈΪÃ÷ÏÔ¡£±ÊÕßÔÚ¹¤×÷ʵ¼ùÖз¢ÏÖ£¬²»Á¼µÄSQLÍùÍùÀ´×ÔÓÚ²»Ç¡µ±µÄË÷ÒýÉè¼Æ¡¢ ......

ÇåÀíSQL Server 2008Êý¾Ý¿âÈÕÖ¾

µÚÒ»²½, ÔÚÊÕËõÇ°ÏȲ鿴ÈÕÖ¾µÄ´óС:
SELECT *
from sysfiles
WHERE name LIKE ' % LOG %'
GO
µÚ¶þ²½, °ÑÊý¾Ý¿âµÄ»Ö¸´Ä£Ê½Éè³É”¼òµ¥”:
ALTER DATABASE ¿âÃû SET RECOVERY SIMPLE
GO
µÚÈý²½, ÔËÐÐcheckpointÖ¸Áî, °Ñdirty pageд½øÊý¾Ý¿â:
CHECKPOINT
GO
µÚËIJ½, ½Ø¶ÏÈÕÖ¾: 
BACKUP ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ