sql´æ´¢¹ý³Ì
ÔÚASP.NetÏîÄ¿ÖÐʹÓô洢¹ý³Ì,Ê×ÏÈ¿ÉÒÔÌá¸ßÊý¾Ý¿âµÄ°²È«ÐÔ£¬Æä´Î¿ÉÒÔÌá¸ßÔËÐÐSQL´úÂëÔËÐеÄËٶȣ¬ÔÚ´óÐÍÏîÄ¿ÖÐÒ»°ãÊDZز»¿ÉÉٵġ£Visual Studio.NetΪSQLµÄ´æ´¢¹ý³ÌÌṩÁËÇ¿´óµÄÖ§³Ö£¬Äú¼È¿ÉÒÔͨ¹ývisual studio.netÀ´Ð½¨´æ´¢¹ý³Ì£¬Ò²¿ÉÒÔÖ±½ÓÔÚSql ServerµÄ²éѯ·ÖÎöÆ÷ÖÐÔËÐУ¬»¹¿ÉÒÔͨ¹ýÆóÒµ¹ÜÀíÆ÷´´½¨£¬Ê¹ÓÃÆðÀ´Ò²·Ç³£·½±ã¡£´ó¼ÒÒ»Ö±¶¼ÎóÈÏΪSQL´æ´¢¹ý³ÌÊÇÒ»¸ö±È½Ï“¸ßÉļ¼Êõ£¬ÆäʵÕÆÎÕÒ»°ãµÄÓï·¨ÊÇûÓÐʲô´óÎÊÌâµÄ£¬¶øÎÒÃÇÔÚʹÓô洢½Ì³ÌÖÐÒ²Ö÷ÒªÊÇÔöɾ¼õµÄ²Ù×÷£¬Ñ§»áʹÓÃÒ»°ãµÄT-SQL¾ÍºÜÈÝÒ×ÉÏÊÖÁË¡£
ÎÒÃÇÏÈÀ´¿´Ò»ÏÂÔÚSql-serverÖÐÊÇÈçºÎ´´½¨Ò»¸ö´æ´¢¹ý³ÌµÄ°É£¬ÎÒÃÇ¿ÉÒÔʹÓÃSQLÃüÁîÓï¾ä´´½¨£¬Ò²¿ÉÒÔͨ¹ýSQL serverÖеÄÆóÒµ¹ÜÀíÆ÷À´´´½¨£¬µ«Æäʵ¶¼ÊÇÀë²»¿ª×Ô¼ºÐ´Óï¾äµÄ£¬µ±È»ÏµÍ³´æ´¢¹ý³ÌÎÒÃǾͲ»ÓÃÈ¥¶¯ËüÁË£¨´æ´¢¹ý³Ì·ÖΪϵͳ´æ´¢¹ý³Ì £¬±¾µØ´æ´¢¹ý³Ì£¬ÁÙʱ´æ´¢¹ý³Ì£¬Ô¶³Ì´æ´¢¹ý³Ì£¬À©Õ¹´æ´¢¹ý³Ì£©£¬¶ø±¾µØ´æ儲過³Ì¾ÍÊÇÎÒ們×Ô¼º編寫µÄ´æ´¢¹ý³Ì£¬ÆäʵҲ½ÐÓû§´æ´¢¹ý³Ì¡£
µ±´´½¨´æ´¢¹ý³ÌʱÐèҪȷ¶¨´æ´¢¹ý³ÌµÄÈý¸ö×é³É²¿·Ö
ËùÓеÄÊäÈë²ÎÊýÒÔ¼°´«¸øµ÷ÓÃÕßµÄÊä³ö²ÎÊý
±»Ö´ÐеÄÕë¶ÔÊý¾Ý¿âµÄ²Ù×÷Óï¾ä°üÀ¨µ÷ÓÃÆäËü´æ´¢¹ý³ÌµÄÓï¾ä
·µ»Ø¸øµ÷ÓÃÕßµÄ״ֵ̬ÒÔÖ¸Ã÷µ÷ÓÃÊdzɹ¦»¹ÊÇʧ°Ü
Ò»¡¢´æ´¢¹ý³Ì´´½¨
1.ÓÃÆóÒµ¹ÜÀíÆ÷À´´´½¨´æ´¢¹ý³Ì;
ÎÒÃÇÏÈ´ò¿ªÆóÒµ¹ÜÀíÆ÷£¬ÕÒµ½ÎÒÃÇÒª´´½¨´æ´¢¹ý³ÌµÄÊý¾Ý¿â£¬Èçͼһ:
ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ÔÚÊý¾Ý¿âÀïÃæÓÐÒ»¸ö´æ´¢¹ý³ÌµÄÏîÄ¿£¬ÎÒÃÇÒªÓõ½µÄ¾ÍÊÇËüÁË£¬Ñ¡Öд洢¹ý³ÌÕâÏÎÒÃÇ¿ÉÒÔ¿´µ½Êý¾Ý¿âÖÐÀïÃæ±¾Éí¾ÍÓкܶà´æ´¢¹ý³Ì´æÔÚµÄÁË£¬²»¹ýÕâЩ¶¼ÊÇÊý¾Ý¿â±¾Éí×Ô´øµÄ£¬ÎÒÃÇ¿ÉÒÔ¿´µ½ËûµÄÀàÐÍÊÇϵͳ£¨Èçͼ¶þ£©£¬Èç¹ûÎÒÃÇ×Ô¼º´´½¨µÄ´æ´¢¹ý³Ì£¬ÀàÐ;ÍÊÇÓû§ÁË.
ÔÚ¿ØÖÆÊ÷µÄ×ó±ß£¬ÎÒÃÇÑ¡Öд洢¹ý³Ìºóµ¥»÷Êó±êÓÒ¼ü£¬¿ÉÒÔ¿´µ½ÓÐÒ»¸ö“´´½¨´æ´¢¹ý³ÌµÄÑ¡Ïî”
Ñ¡ÖÐÕâÏ¾Í»á³öÏÖеĴ°¿ÚÁË£¬Õâ¸ö´°¿Ú¾ÍÊÇÓÃÀ´Ð´´æ´¢¹ý³ÌµÄÁË
ÔÚʵ¼ÊÔËÓùý³ÌÖУ¬ÎÒÃÇËù´´½¨µÄ´æ´¢¹ý³Ì²¢²»ÊÇÏëÏñÖеÄÕâô¸´ÔÓ£¬¶øÉÏÃæµÄÕâЩ²ÎÊýÒ²²»ÊǶ¼ÒªÓÃÉÏ£¬µ«Ò»°ãÎÒÃÇÔÚÓòéѯ·ÖÎöÆ÷´´½¨´æ´¢¹ý³ÌÇ°£¬¶¼»áͨ¹ýÏÂÃæÕâÌõÓï¾äÀ´²éѯһÏ£¬ÔÚÊý¾Ý¿âÖÐÊÇ·ñÒѾ´æÔÚÏàͬÃüÃûµÄ´æ´¢¹ý³Ì,Èç¹û´æÔڵĻ°£¬ÔòÏÈɾ³ý¡£
If exists(select name from sysobjects where name=’´æ´¢¹ý³ÌÃû’ and type=’p’)
Drop procedure ‘´æ´¢¹ý³ÌÃû’
Go
ÔÚÕâÀÎÒÃÇÒ²¾Í
Ïà¹ØÎĵµ£º
1.¼¯ºÏ²Ù×÷
ѧϰoracleÖм¯ºÏ²Ù×÷µÄÓйØÓï¾ä£¬ÕÆÎÕunion,union all,minus,interestµÄʹÓÃ,Äܹ»ÃèÊö½áºÏÔËË㣬²¢ÇÒÄܹ»½«¶à¸ö²éѯ×éºÏµ½Ò»¸ö²éѯÖÐÈ¥£¬Äܹ»¿ØÖÆÐзµ»ØµÄ˳Ðò¡£
°üº¬¼¯ºÏÔËËãµÄ²éѯ³ÆΪ¸´ºÏ²éѯ¡£¼û±í¸ñ1-1
±í1-1
Operator Returns   ......
һֱûÓÐÕÒµ½Ò»Öֺõķ½·¨À´ÒýÓÃÓзµ»ØÖµµÄ´æ´¢¹ý³ÌµÄ·½·¨£¬Ê¹ÎÒÔÚÌí¼ÓÊý¾ÝÖÐ×ßÁ˲»ÉÙµÄÍä·£¬×î½ü£¬ÔÚ²éÔÄÁË´óÁ¿µÄ×ÊÁÏÖ®ºó£¬ÖÕÓÚÔÚ΢ÈíµÄÒ»¸öʵÀýÖÐÕÒµ½ÁËÒ»ÖÖÁ¼ºÃµÄ·½·¨¡£
Ê×ÏȱàдºÃÒ»Óзµ»ØÖµµÄ´æ´¢¹ý³Ì
create procedure proc_name
@para1 nchar(20), --ÊäÈë²ÎÊý
&n ......
ÔÚSQL ServerÖгöÓÚÊý¾Ý°²È«µÄ¿¼ÂÇ£¬ËùÒÔÐèÒª¶¨Æڵı¸·ÝÊý¾Ý¿â¡£¶ø±¸·ÝÊý¾Ý¿âÒ»°ãÓÖÊÇÔÚÁ賿ʱ¼ä»ù±¾Ã»ÓÐÊý¾Ý¿â²Ù×÷µÄʱºò½øÐУ¬ËùÒÔÎÒÃDz»¿ÉÄÜÒªÇó¹ÜÀíԱÿÌìÊص½ÍíÉÏ1µãÈ¥±¸·ÝÊý¾Ý¿â¡£ÒªÊµÏÖÊý¾Ý¿âµÄ¶¨Ê±×Ô¶¯±¸·Ý£¬×î³£Óõķ½Ê½¾ÍÊÇʹÓÃSQL Server´úÀíÖеÄ×÷Òµ¡£Æô¶¯SQL Server Agent·þÎñ£¬È»ºóÔÚÆäÖÐн¨×÷Òµ£¬×÷ÒµÖÐÌí¼ ......
µÚʮһÌ⣺
Óбístudents(name,class,grade),ÇëÓñê×¼sqlÓï¾äÍê³É
name class grade
ÕÅÈý Êýѧ 81
ÀîËÄ ÓïÎÄ 70
ÍõÎå Êýѧ 90
ÕÅÈý ÓïÎÄ 60
ÀîËÄ Êýѧ 100
ÍõÎå ÓïÎÄ 90
ÍõÎå Ó¢Óï 81
ÒªÇó: ÓÃsqlÓï¾äÊä³ö¸÷ÃŹ¦¿Î¶¼´óÓÚ80·ÖµÄͬѧÐÕÃû?
create table students (
name varchar(25),
class varchar(25), ......
µÚ¶þÊ®Ì⣺
ÔõôÑù³éÈ¡Öظ´¼Ç¼
񡜧
id name
--------
1 test1
2 test2
3 test3
4 test4
5 test5
6 test6
2 test2
3 test3
2 test2
6 test6
²é³öËùÓÐÓÐÖظ´¼Ç¼µÄÊý¾Ý£¬ÓÃÒ»¾äsql À´ÊµÏÖ
create table D(
id varchar (20),
name varchar (20)
)
insert into D values('1','test1')
insert into D val ......