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

ѧϰSQL SERVERÓαêµÄʹÓÃ

 ¡¡¡¡ÔÚÕâÒ»²½ÖУ¬ÐèÒªÖ¸¶¨ÓαêµÄÊôÐԺ͸ù¾ÝÒªÇó²úÉúµÄ½á¹û¼¯¡£ÓÐÁ½ÖÖ·½·¨¿ÉÒÔÖ¸¶¨Ò»¸öÓαꡣ
¡¡¡¡ÐÎʽ1£¨ANSI 92£©
DECLARE cursor_name [INSENSITIVE] [SCROLL] CURSOR
FOR select_statement
[FOR {READ ONLY | UPDATE ][OF column_list]}]
¡¡¡¡ÐÎʽ2
DECLARE cursor_name CURSOR
[LOCAL | GLOBAL]
[FORWARD_ONLY | SCROLL]
[STATIC | KEYSET | DYNAMIC]
[READ_ONLY | SCROLL_LOCKS | OPTIMISTIC]
FOR select_statement
[FOR {READ ONLY | UPDATE ][OF column_list]}]
INSENSITIVE¹Ø¼ü×ÖÖ¸Ã÷ҪΪ¼ìË÷µ½µÄ½á¹û¼¯½¨Á¢Ò»¸öÁÙʱ¿½±´£¬ÒÔºóµÄÊý¾Ý´ÓÕâ¸öÁÙʱ¿½±´ÖлñÈ¡¡£Èç¹ûÔÚºóÀ´Óα괦ÀíµÄ¹ý³ÌÖУ¬Ô­Óлù±íÖÐÊý¾Ý·¢ÉúÁ˸ı䣬ÄÇôËüÃǶÔÓÚ¸ÃÓαê¶øÑÔÊDz»¿É¼ûµÄ¡£ÕâÖÖ²»Ãô¸ÐµÄÓα겻ÔÊÐíÊý¾Ý¸ü¸Ä¡£
¡¡¡¡SCROLL¹Ø¼ü×ÖÖ¸Ã÷Óαê¿ÉÒÔÔÚÈÎÒâ·½ÏòÉϹö¶¯¡£ËùÓеÄfetchÑ¡Ïfirst¡¢last¡¢next¡¢relative¡¢absolute£©¶¼¿ÉÒÔÔÚÓαêÖÐʹÓá£Èç¹ûºöÂÔ¸ÃÑ¡ÏÔòÓαêÖ»ÄÜÏòÇ°¹ö¶¯£¨next£©¡£
¡¡¡¡Select_statementÖ¸Ã÷SQLÓï¾ä½¨Á¢µÄ½á¹û¼¯¡£Transact SQLÓï¾äCOMPUTE¡¢COMPUTE BY¡¢FOR BROWSEºÍINTOÔÚÓαêÉùÃ÷µÄÑ¡ÔñÓï¾äÖв»ÔÊÐíʹÓá£
¡¡¡¡READ ONLYÖ¸Ã÷ÔÚÓαê½á¹û¼¯Öв»ÔÊÐí½øÐÐÊý¾ÝÐ޸ġ£
¡¡¡¡UPDATE¹Ø¼ü×ÖÖ¸Ã÷ÓαêµÄ½á¹û¼¯¿ÉÒÔÐ޸ġ£
¡¡¡¡OF column_listÖ¸Ã÷½á¹û¼¯ÖпÉÒÔ½øÐÐÐ޸ĵÄÁС£È±Ê¡Çé¿öÏ£¨Ê¹ÓÃUPDATE¹Ø¼ü×Ö£©£¬ËùÓеÄÁж¼¿É½øÐÐÐ޸ġ£
¡¡¡¡LOCAL¹Ø¼ü×ÖÖ¸Ã÷ÓαêÊǾֲ¿µÄ£¬ËüÖ»ÄÜÔÚËüËùÉùÃ÷µÄ¹ý³ÌÖÐʹÓá£
¡¡¡¡GLOBAL¹Ø¼ü×ÖʹµÃÓαê¶ÔÓÚÕû¸öÁ¬½ÓÈ«¾Ö¿É¼û¡£È«¾ÖµÄÓαêÔÚÁ¬½Ó¼¤»îµÄÈκÎʱºò¶¼ÊÇ¿ÉÓõġ£Ö»Óе±Á¬½Ó½áÊøʱ£¬Óαê²Å²»ÔÙ¿ÉÓá£
FORWARD_ONLYÖ¸Ã÷ÓαêÖ»ÄÜÏòÇ°¹ö¶¯¡£
¡¡¡¡STATICµÄÓαêÓëINSENSITIVEµÄÓαêÊÇÏàͬµÄ¡£
¡¡¡¡KEYSETÖ¸Ã÷Ñ¡È¡µÄÐеÄ˳Ðò¡£SQL Server½«´Ó½á¹û¼¯Öд´½¨Ò»¸öÁÙʱ¹Ø¼ü×Ö¼¯¡£Èç¹û¶ÔÊý¾Ý¿âµÄ·Ç¹Ø¼ü×ÖÁнøÐÐÁËÐ޸ģ¬ÔòËüÃǶÔÓαêÊǿɼûµÄ¡£ÒòΪÊǹ̶¨µÄ¹Ø¼ü×Ö¼¯ºÏ£¬ËùÒԶԹؼü×ÖÁнøÐÐÐ޸ĻòвåÈëÁÐÊDz»¿É¼ûµÄ¡£
¡¡¡¡DYNAMICÖ¸Ã÷Óα꽫·´Ó³ËùÓжԽá¹û¼¯µÄÐ޸ġ£
¡¡¡¡SCROLL_LOCKÊÇΪÁ˱£Ö¤Óαê²Ù×÷µÄ³É¹¦£¬¶ø¶ÔÐ޸Ļòɾ³ý¼ÓËø¡£
¡¡¡¡OPTIMISTICÖ¸Ã÷ÄÄЩͨ¹ýÓαê½øÐеÄÐ޸ĻòÕßɾ³ý½«²»»á³É¹¦¡£
¡¡¡¡×¢Ò⣺
¡¡¡¡· Èç¹ûÔÚSELECTÓï¾äÖÐʹÓÃÁËDISTINCT¡¢UNION¡¢GROUP BYÓï¾ä£¬ÇÒÔÚÑ¡ÔñÖаüº¬Á˾ۺϱí´ïʽ£¬ÔòÓαê×Ô¶¯ÎªINSENSITIVEµÄÓαꡣ
¡¡¡¡· Èç¹û»ù±íûÓÐΨһµÄË÷Òý£¬ÔòÓαê´


Ïà¹ØÎĵµ£º

SQL server×Ó²éѯ

exec xp_cmdshell 'md E:\project'
--ÏÈÅжÏÊý¾Ý¿âÊÇ·ñ´æÔÚÈç¹û´æÔÚ¾Íɾ³ý
if exists(select * from sysdatabases where name='bbsDB')
drop database bbsDB
--´´½¨Êý¾Ý¿âÎļþ
create database bbsDB
--Ö÷Êý¾Ý¿âÎļþ
 on primary
(
 name='bbsDB_data',--ΪÖ÷ÒªÊý¾Ý¿âÎļþÃüÃû
 filename='E:\proj ......

²éѯ°à¼¶Öм°¸ñ£¬Ò»°ã£¬ÓÅÐãµÄÈËÊýµÄsqlÓï¾ä

select a.ClassName,a.CourseName,sum(²»¼°¸ñ) as ²»¼°¸ñ,sum(²î) as ²î,sum(ÖеÈ) as ÖеÈ,sum(ºÃ) as ºÃ ,sum(²»¼°¸ñ)+sum(²î)+sum(ÖеÈ)+sum(ºÃ) as °à¼¶×ÜÈËÊý from (select StudentID,ClassName,CourseName,1 as ²»¼°¸ñ,0 as ²î,0 as ÖеÈ,0 as ºÃ from StudentScore where ScoreRemark='fail' union all
select Stu ......

SQL Server ÓÅ»¯SELECTÓï¾ä·½·¨

 
±¾ÎÄת×Ô£ºhttp://industry.ccidnet.com/art/1106/20070514/1080519_1.html
±¾ÎÄÊÇSQL Server SQLÓï¾äÓÅ»¯ÏµÁÐÎÄÕµĵÚһƪ¡£¸ÃϵÁÐÎÄÕÂÃèÊöÁËÔÚMicosoft’s SQLServer2000¹ØϵÊý¾Ý¿â¹ÜÀíϵͳÖÐÓÅ»¯SELECTÓï¾äµÄ»ù±¾¼¼ÇÉ£¬ÎÒÃÇÌÖÂ۵ļ¼ÇÉ¿ÉÔÚMicrosoft's SQL Enterprise Manager»ò Microsoft SQL Query Anal ......

SQL server 1068´íÎó

ÏÖÏó£º
   ÎҵĵçÄÔ--¹ÜÀí--·þÎñ--mssqlserver ·þÎñ --Æô¶¯
   ±¨´í£¬1068£¬
   »òÕߣ¬sqlserver ÅäÖùÜÀíÆ÷ÖÐSqlServer Ö÷·þÎñÆô¶¯ ±¨´í Ìáʾ˵ÒÀ´æµÄ·þÎñ»òÕß×é¼þûÓÐÆô¶¯£¬
Ô­Òò£ºÎÒÊDzËÄñ£¬²»Ì«Àí½âµ½µ×ʲôԭÒò£¬µ«ÊÇÕÒµ½Á˽â¾ö·½·¨
  
½â¾ö·½·¨£º
   SqlSe ......

¼¸¸öSQL ServerÓï¾äºÍ´æ´¢¹ý³Ì

-- ======================================================
--ÁгöSQL SERVER ËùÓÐ±í£¬×Ö¶ÎÃû£¬Ö÷¼ü£¬ÀàÐÍ£¬³¤¶È£¬Ð¡ÊýλÊýµÈÐÅÏ¢
--ÔÚ²éѯ·ÖÎöÆ÷ÀïÔËÐм´¿É,¿ÉÒÔÉú³ÉÒ»¸ö±í£¬µ¼³öµ½EXCELÖÐ
-- ======================================================
SELECT
       (case when a. ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ