sql server ´æ´¢¹ý³Ì¼°´¥·¢Æ÷
Ò»Ö±¶¼ÏëÕÒ¸öʱ¼äÑо¿Ò»Ï£¬½ñÌ컨ÁËÒ»Ììʱ¼äȥʵ¼ùÁËһϣ¬·Ç³£ÓÐÓ᣿ÉÒÔ˵ÊÇÊý¾Ý¿âÀïÃæµÄ¾«»ª°É¡£»¹ºÃÎÒ½ñÌìȥŪÁ˼¸Ï£¬Ëä˵¶¼ÊÇЩ¼òµ¥µÄÓï¾ä£¬µ«ÊÇ×îÆðÂëÖªµÀÒÔºóÔÚÏîÄ¿¸ÃÔõôȥ×öÁË¡£ Ïл°ÉÙ˵¡£½øÈëÕýÌâ¡£
1.´´½¨SQL´æ´¢¹ý³Ì:
CREATE PROCEDURE stu_proc1//Ö¸¶¨¹ý³ÌÃû
@Sno varchar(50) ='7000803068',//¶¨Òå²ÎÊýÒÔ¼°Ä¬ÈÏÖµ
AS//Ö´ÐÐSQLÓï¾ä
select * from Student
where Sno=@Sno
GO
Declare @XXXÉùÃ÷±äÁ¿
set @XXX=XXXÉ趨±äÁ¿Öµ
ͬʱÀïÃæÒ²ÓÐif else whileµÈÓï¾ä²»¹ýµÃ¼ÓÉÏbegin end
2.Ö´Ðд洢¹ý³Ì
Execute stu_proc1 @Sno='XXX' @Sname='XXXX'
Æäʵ¿ÉÒÔ°Ñ´æ´¢¹ý³Ì¿´³ÉÒ»¸öCÓïÑԵĺ¯Êý¡£º¯ÊýÃûÊÇ´æ´¢¹ý³ÌÃû£¬ÐβÎÊÇÒ²ÊÇÀïÃæµÄ²ÎÊý£¬ÀïÃ滹Óоֲ¿±äÁ¿£¬Í¬Ê±Ò²¿ÉÉ趨ֵ¡£Ò²¿ÉÒÔ·µ»ØÖµ£¬ÓÃreturnÓï¾ä¡£ÀïÃæ¿ÉÒÔÓõ½if else,whileÓï¾ä¡£µ«ÊÇCÀïÃæµÄº¯Êý¹¦ÄÜ»á¸ü´ó£¬²»ÄܵÈͬ£¬Ö»ÄÜ×ö±È½Ï¡£Ð´´æ´¢¹ý³ÌÒ²ÓеãÏñд¸öº¯ÊýÒ»Ñù¡£
ͬʱÔÚJAVAÓïÑÔÖÐÒ²¿ÉÒÔµ÷Óô洢¹ý³Ì£¬ÀàËÆCÀïµ÷Óú¯Êý¡£É趨ÐβÎÖµ¡£
3.JDBCÖе÷Óô洢¹ý³Ì
CallableStatement¶ÔÏó
String sql="{call stu_proc1(?,?)}";
String firstVal="";
String secondVal="";
Class.forName();
Connection conn=DriverManager.getConnection("","","");
CallableStatement stmt=conn.prepareCall(sql);
stmt.setString(1,firstVal);
stmt.setString(2,secondVal);
ResultSet rs=stmt.executeQuery();
´æ´¢¹ý³Ì¿ÉÒÔÌá¸ß·ÃÎÊÊý¾Ý¿âµÄÐÔÄܺÍËٶȡ£
´¥·¢Æ÷ÊÇÒ»ÖÖÌØÊâµÄ´æ´¢¹ý³Ì£¬Ö÷ÒªÓÃÓÚupdate,insert,deleteÕâÈýÖÖÓï¾ä£¬Ö÷ÒªÊÇ´¦Àí±íÓë±íÖ®¼äµÄ¹ØÁª£¬Ò²¾ÍÊÇÔ¼ÊøÐÔ°É¡£Í¬Ê±Óжþ¸ö±íinserted£¨²åÈë±í£©,deleted(ɾ³ý±í)¶øupdate¿ÉÒÔ¿´³ÉÏÈɾ³ý£¬È»ºó²åÈë.±ÈÈ磬µ±ÒªÉ¾³ýÒ»¸öѧÉúʱ£¬Í¬Ê±¸ÃѧÉúµÄÑ¡¿Î¼Ç¼ҲÊÇҪɾ³ýµÄ£¬Õâʱ¿ÉÒÔÔÚѧÉú±í½ø½¨¸ö´¥·¢Æ÷¾Í¿ÉÒÔʵÏÖÕâÖÖ¹¦ÄÜ¡£
´¥·¢Æ÷¾ÍÊÇ¿ÉÒÔ½øÐйØÁª²Ù×÷£¬¶øµ¥µ¥SQLÓï¾ä²»ÄÜ×öµ½ÕâÒ»µã¡£
CREATE TRIGGER StudentDelete ON [dbo].[Student]
FOR DELETE
AS
delete from SC where SC.Sno=(select Sno from deleted)
Óï¾äÐÎʽ¸ú´æ´¢¹ý³ÌÊÇÒ»Öµģ¬ÒòΪ´¥·¢Æ÷±¾Éí¾ÍÊÇÒ»ÖÖ´æ´¢¹ý³Ì.
×ÊÁÏÒýÓÃ:http://www.258wx.com/
Ïà¹ØÎĵµ£º
SQL ÃüÁî
Õⲿ·Ö°üº¬ÄÇЩ PostgreSQL Ö§³ÖµÄ SQL ÃüÁîµÄÐÅÏ¢£®ÕâÀïµÄ "SQL" ¾ÍÊǸÃÓïÑÔͨ³£µÄº¬Ò壻 ÿÌõÃüÁîµÄÓë±ê×¼ÓйصļæÈÝÐÔµÄÐÅÏ¢¿ÉÒÔÔÚÏà¹ØµÄ²Î¿¼Ò³ÖÐÕÒµ½£®
Table of Contents
ABORT -- Í˳öµ±Ç°ÊÂÎñ
ALTER GROUP -- Ïò×éÖÐÔö¼ÓÓû§»ò´Ó×éÖÐɾ³ýÓû§
ALTER USER -- ¸Ä±äÊý¾ ......
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
¡¡¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý ......
×î½üÒ»Ö±ÔÚѧϰSQL serverµÄÄÚÈÝ¡£×òÌ쿼ÁËÒ»ÏÂÊÔ¡£¸Ð¾õÕæµÄÊDz»ÈÝÒ×°¡¡£ÌرðÊÇһЩ¸´ÔӵIJéѯ¡£¸ãµÃÎÒÍ·»èÄÔÕ͵ġ£²»¹ýÒ²ÊÇÓÉÓÚ×Ô¼ºµÄ֪ʶÕÆÎյĻ¹²»¹»Ôúʵ°¡¡£ËùÒÔ½ñÌ츴ϰÁËÒ»ÏÂT-SQlÓï¾äµÄÔöɾ¸Ä²é¡£·¢ÏÖµÄÈ·ÊÇÓкܶ඼Íü¼ÇÁË¡£ÏÖÔڰѽá¹ûд³öÀ´¡£ÒÔºó¿É²»ÒªÍüÁËѽ¡£
--SQLÓï¾ä¸´Ï° --Ò»,²åÈëinsertÓï¾ä --1,ins ......
»ùÓÚSQL Server ·ÖÒ³´æ´¢¹ý³ÌµÄÑݽø ÊÕ²Ø
Õë¶ÔÊý¾Ý¿âÊý¾ÝÔÚUI½çÃæÉϵķÖÒ³ÊÇÀÏÉú³£Ì¸µÄÎÊÌâÁË£¬ÍøÉϺÜÈÝÒ×ÕÒµ½¸÷Ö֓ͨÓô洢¹ý³Ì”´úÂ룬¶øÇÒÓÐЩ»¹¶¨ÖƲéѯÌõ¼þ£¬¿´ÉÏȥʹÓúܷ½±ã¡£±ÊÕß´òËãͨ¹ý±¾ÎÄÒ²À´¼òµ¥Ì¸Ò»Ï»ùÓÚSQL SERVER 2000µÄ·ÖÒ³´æ´¢¹ý³Ì£¬Í¬Ê±Ì¸Ì¸SQL SERVER 2005Ï·ÖÒ³´æ´¢¹ý³ÌµÄÑ ......
½ñÌìÔÚÏîÄ¿ÖÐÓÐÒ»ÎÊÌ⣬ÔÚÍøÉϲéѯÁËcaseµÄÓ÷¨£¬Ìû³öÀ´ºÍ´ó¼Ò·ÖÏíÏ¡£
ÎÊÌâÃèÊö£ºÔÚÒ»ÕűíÖÐÓÐÒ»×Ö¶ÎbitÀàÐÍ£¬±íʾ´ËÌõÊý¾ÝÊÇ·ñ±»Ëø¶¨£¬ÔÚÒ³ÃæÉÏÓÐÒ»°´Å¥ÊǶԴËÌõÊý¾Ý½øÐÐËø¶¨ºÍ½âËøµÄ£¬Ñ¡ÔñÒ³ÃæÖеÄÊý¾Ý£¬µã»÷Õâ¸ö°´Å¥£¬Èç¹ûÕâÌõÊý¾ÝÊÇËø¶¨µÄ£¬¾Í½âËø£»Èç¹ûÊÇδ˵¶¨µÄ¾ÍËø¶¨£¬ÕâÑù¾ÍÓÃÒ»ÌõÓï¾äÀ´ÊµÏÖ¡£ºóÀ´Ï ......