SqlServerÓαêÀí½â
Óαê²Ù×÷µÄÁù²½Öè:
¡ôÔÚÿ´ÎÔÚ´´½¨ÓαêµÄʱºò¶¼ÎÊÎÊ×Ô¼º,ÓÃʲô±ðµÄ·½·¨¿ÉÒÔ±ÜÃâʹÓÃÓαê,ÄÇôÄã¾Í²½ÈçÉè¼ÆµÄÕý¹æÁË.
1.ÉùÃ÷
2.´ò¿ª
3.Ó¦ÓÃ/²Ù×÷
4.¹Ø±Õ.
5.ÊÍ·Å
ÉùÃ÷ÓαêµÄ»ù±¾Óï·¨ÈçÏÂ:
Declare <cursor name> cursor
For <select statement>
°¸Àý1: MySchool
if exists(select * from sysobjects where name='cursc')
drop proc cursc
Go
create procedure cursc
as
declare
@question varchar(210), --ÎÒÃDZØÐëÉùÃ÷±äÁ¿À´´æ·ÅµÃµ½µÄ¼Ç¼
@a varchar(50),
@b varchar(50),
@c varchar(50),
@d varchar(50),
@answer varchar(50),
@num int
declare MyCursor cursor --ÉùÃ÷ÎÒÃǵÄÓαê
Global --È«¾Ö ÓαêµÄ·¶Î§»¹ÓÐÒ»¸öÊǾֲ¿(Local)
for select question ,OptionA,OptionB,OptionC,OptionD,Answer from question --¶ÔÓ¦µÄSQLÓï¾ä ºóÃæ´ò¿ªÓαê¾ÍÊÇ´ò¿ª
set @num=1 --ÉèÖñêÁ¿±íʾÓαêµÄÒƶ¯
open MyCursor --´ò¿ªÎÒÃǵÄÓαêÕâʵ¼ÊÖ´ÐÐÁËFor´Ó¾äµÄÖ÷Ìå²éѯ,µ«ÎÒÃÇÈÔȻûÓн«Êý¾Ý
--·ÅÔÚºÏÊʵÄλÖýøÐкÏÊʵĴ¦Àí,Òò´ËÎÒÃÇÐèÒª´¦ÀíÒ»×éÊÂÇé.
--1.»ñÈ¡µÚÒ»ÌõÀí·»òÕßFetch
&n
Ïà¹ØÎĵµ£º
SQL Server Ö§³ÖÁÙʱ±í¡£ÁÙʱ±í¾ÍÊÇÄÇЩÃû³ÆÒÔ¾®ºÅ (#) ¿ªÍ·µÄ±í¡£Èç¹ûµ±Óû§¶Ï¿ªÁ¬½ÓʱûÓгýÈ¥ÁÙʱ±í£¬SQL Server ½«×Ô¶¯³ýÈ¥ÁÙʱ±í¡£ÁÙʱ±í²»´æ´¢ÔÚµ±Ç°Êý¾Ý¿âÄÚ£¬¶øÊÇ´æ´¢ÔÚϵͳÊý¾Ý¿â tempdb ÄÚ¡£
ÁÙʱ±íÓÐÁ½ÖÖÀàÐÍ£º
±¾µØÁÙʱ±í
ÒÔÒ»¸ö¾®ºÅ (#) ¿ªÍ·µÄÄÇЩ±íÃû¡£Ö»ÓÐÔÚ´´½¨±¾µØÁÙʱ±íµÄÁ¬½ÓÉϲÅÄÜ¿´ ......
ÉÏ´Î×öÁ˸öÏîÄ¿£¬Éæ¼°µ½Êý¾Ý¿âµÄ»¹ÔºÍ»Ö¸´£¬µ½ÍøÉÏÕÒÁËһϣ¬ÊÇÀûÓÃSQLDMOʵÏֵģ¬Ö»ÒªÌí¼ÓSQLDMOÒýÓþͺÃÁË£¬È»ºóÀûÓÃϱߵÄÀàµÄ·½·¨¾Í¿ÉÒÔʵÏÖÁË¡£
ÎÒ°ÑÔ×÷ÕßµÄÀàÀ©³äÁËһϣ¬¿ÉÒÔ×Ô¶¯Ê¶±ðweb.configÀï µÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®£¬¿ÉÒÔͨ¹ý±äÁ¿ÉèÖû¹Ô»Ö¸´µÄÐÅÏ¢¡£
ÐèҪעÒâµÄʱ»¹Ô£¬»¹ÔµÄʱºòÎÊÌ ......
select identity(int,1,1) as col_id , * into temp from uep.dbo.A_experiment
select * from temp where col_id between 50 and 60
drop table temp ......
Ñ¡ÔñÖ¸¶¨ÌõÊýÓï¾ä£º
db2£ºselect * from tabname fetch frist n rows only
informix£ºselect first n *
from tabname
oralce£ºselect * from tabname where rownum <= n
sql server :select top n * from tabname ......