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

¹ØÓÚSql´æ´¢¹ý³Ì


SQL ÖеĴ洢¹ý³Ì£º
1.ÔÚ½¨Á¢´æ´¢¹ý³Ì֮ǰ¼ì²éËùÃüÃûµÄ´æ´¢¹ý³ÌÊÇ·ñÓ¦¾­´æÔÚ¡££¨ÒòΪÈç¹ûͬÃû´æ´¢¹ý³ÌÒѾ­´æÔÚ£¬ÐµĴ洢¹ý³Ì½«²»±»½¨Á¢£©
if exists(select * from sysobject where name='proc name' and type='p')
drop proc proc name
   go
2.¶¨Òå´æ´¢¹ý³Ì
create proc test
@gradel int, --¶¨Òå±äÁ¿
@gradeh int output --¶¨ÒåÊä³ö±äÁ¿
as
...
go
3.Ö´Ðд洢¹ý³Ì
declare @l int,@h int
exec proc test 34,@h output
print @h
----------------------------------------------
ÏÂÃæÒÔÒ»¸öÀý×Ó˵Ã÷£º
ÊäÈëÁ½¸ö·ÖÊý£¬ÒªÇóдÁ½¸ö´æ´¢¹ý³Ì£¬Ò»¸ö¶ÔÊäÈë·ÖÊýÅÅÐò£¬ÁíÒ»¸ö²éѯÁ½·ÖÊý¶ÎÖ®¼äµÄ³É¼¨£º
Ò»¹²ÓÐÈý¸ö±í£º
s±í£º£¨s#£ºÑ§ÉúºÅ£¬sname:ѧÉúÐÕÃû£¬age:ÄêÁ䣬sex:ÐÔ±ð£©
c±í£º£¨c#£º¿Î³ÌºÅ£¬cname:¿Î³ÌÃû£¬teacher£ºÀÏʦ£©
sc±í£º£¨s#,c#,grade)
if exists(select * from sysobjects where name='sort'
          and type='p')
drop proc sort
go --¶¨ÒåÒ»¸ö´æ´¢¹ý³ÌÓÃÓÚÅÅÐò
create proc sort
@high int,
@low int,--¶¨ÒåÁ½¸öÊäÈë²ÎÊý
@hi int output,
@lo int output--¶¨ÒåÁ½¸öÊä³ö²ÎÊý
as
if @high<@low
begin
set @high=@high+@low
set @low=@high-@low
set @high=@high-@low
set @hi=@high
set @lo=@low
end
go --Èç¹ûδ°´Ë³ÐòÊäÈëÔòÅÅÐò
if exists(select * from sysobjects where name='search' and type='p')
drop proc search
go --¶¨ÒåÒ»¸ö´æ´¢¹ý³ÌÓÃÓÚ²éÕÒÏàÓ¦·¶Î§µÄ¼Ç¼
create proc search
@gradeh int,
@gradel int
as
select * from sc where grade between @gradel and @gradeh
if @@rowcount=0
print '²éѯʧ°Ü'
go
declare @h int,@l int
exec testpro 70,90,@h output,@l output
exec search @h,@l
²Î¿¼£ºhttp://hi.baidu.com/rosalind1717/blog/item/bcb26ceea5a418212cf534ce.html
http://hi.baidu.com/isbx/blog/item/3e06ae514c35ac878d543094.html


Ïà¹ØÎĵµ£º

SQL ÓÃexists´úÌæÈ«³ÆÁ¿´Ê

ѧϰsqlµÄ±Ø¾­ÎÊÌâ¡£
ѧÉú±ístudent (idѧºÅ     SnameÐÕÃû       SdeptËùÔÚϵ)  
¿Î³Ì±íCourse           (crscode¿Î³ÌºÅ       name¿Î³ÌÃû)  
ѧÉúÑ¡¿Î±ítranscript           (studidѧºÅ &nbs ......

SQL With cube

ÏÐÀ´Ð´ÏÂwith cubeµÄÓ÷¨
cubeÔËËã·ûÔÚ SELECT Óï¾äµÄ GROUP BY ×Ó¾äÖÐÖ¸¶¨¡£¸ÃÓï¾äµÄÑ¡ÔñÁбíÓ¦°üº¬Î¬¶ÈÁк;ۺϺ¯Êý±í´ïʽ¡£GROUP BY Ó¦Ö¸¶¨Î¬¶ÈÁк͹ؼü×Ö WITH CUBE¡£½á¹û¼¯½«°üº¬Î¬¶ÈÁÐÖи÷ÖµµÄËùÓпÉÄÜ×éºÏ£¬ÒÔ¼°ÓëÕâЩά¶ÈÖµ×éºÏÏàÆ¥ÅäµÄ»ù´¡ÐÐÖеľۺÏÖµ¡£
ÏÈ¿´ÏÂ±í£º
ÎÒÃÇÒÔid¾ÛºÏ²éѯ³öƽ¾ù·Ö
ÕâÒ»ÌõSQLÓï¾äÓ ......

SqlÊý¾ÝÓÅ»¯·½°¸

1¡¢Ê¹ÓÃË÷ÒýÀ´¸ü¿ìµØ±éÀú±í¡£
ȱʡÇé¿öϽ¨Á¢µÄË÷ÒýÊÇ·ÇȺ¼¯Ë÷Òý£¬µ«ÓÐʱËü²¢²»ÊÇ×î¼ÑµÄ¡£ÔÚ·ÇȺ¼¯Ë÷ÒýÏ£¬Êý¾ÝÔÚÎïÀíÉÏËæ»ú´æ·ÅÔÚÊý¾ÝÒ³ÉÏ¡£ºÏÀíµÄË÷ÒýÉè¼ÆÒª½¨Á¢ÔÚ¶Ô¸÷ÖÖ²éѯµÄ·ÖÎöºÍÔ¤²âÉÏ¡£
Ò»°ãÀ´Ëµ£º
a.ÓдóÁ¿Öظ´Öµ¡¢ÇÒ¾­³£Óз¶Î§²éѯ£¨ > ,< £¬> =,< =£©ºÍorder by¡¢group by·¢ÉúµÄÁУ¬¿É¿¼
Âǽ ......

SQL distinctÓ÷¨¡¡¼òµ¥group by ÃüÁî


distinctÕâ¸ö¹Ø¼ü×ÖÓÃÀ´¹ýÂ˵ô¶àÓàµÄÖظ´¼Ç¼ֻ±£ÁôÒ»Ìõ£¬µ«ÍùÍùÖ»ÓÃËüÀ´·µ»Ø²»Öظ´¼Ç¼µÄÌõÊý£¬¶ø²»ÊÇÓÃËüÀ´·µ»Ø²»ÖؼǼµÄËùÓÐÖµ¡£ÆäÔ­ÒòÊÇdistinctÖ»ÓÐÓöþÖØÑ­»·²éѯÀ´½â¾ö£¬¶øÕâÑù¶ÔÓÚÒ»¸öÊý¾ÝÁ¿·Ç³£´óµÄÕ¾À´Ëµ£¬ÎÞÒÉÊÇ»áÖ±½ÓÓ°Ï쵽ЧÂʵġ£
ÏÂÃæÏÈÀ´¿´¿´Àý×Ó£º
table±í
×Ö¶Î1      ×Ö¶ ......

SQL outputʹÓÃ

SQL°æ£º
alter proc testguo
(
    @cityid int,
    @cityname nvarchar(100) output
)
as
select @cityname =  city_name from BA_Hot_City where cityid = @cityid
select @cityname
go
declare @cityname nvarchar(100)
exec testguo 1,@cityname output
ÁíÒ»°æ£º
ht ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ