SQL 2005 ´æ´¢¹ý³Ì µ÷ÊÔ
SQL 2005 µÄ´æ´¢¹ý³ÌºÍ´¥·¢Æ÷µ÷ÊԴ󷨣¨Ô´´£©
www.chengchen.net ³Ì³¿
×òÌìÍíÉÏÎÒÕÒ±éÁË»¥ÁªÍøҲûÓз¢ÏÖ¹ØÓÚSQL2005´æ´¢¹ý³ÌºÍ´¥·¢Æ÷µÄµ÷ÊÔ·½·¨£¬Ñо¿µ½Á賿2µã¶àÖÓ£¬ÖÕÓÚÕÒµ½·½·¨ÁË£¬²»¸É¶ÀÏí£¬ÄóöÀ´·ÖÏí¡£Èç¹ûҪתÔØ£¬Çë±£Áô°æȨ£¬Ð»Ð»£¡
ÔÚSQL2000ÖУ¬ÎÒÃÇÏëÒªµ÷ÊÔ´æ´¢¹ý³Ì·Ç³£¼òµ¥£¬Ö»ÐèÒªÔÚ¶ÔÏóä¯ÀÀÆ÷ÖÐÕÒµ½´æ´¢¹ý³Ì£¬È»ºóµã»÷Êó±êÓÒ¼üÑ¡Ôñ“Ö´ÐУ¨µ÷ÊÔ£©”¾Í¿ÉÒÔµ¯³öÒ»¸ö¹¤¾ßÀ¸³öÀ´£¬½øÐе÷ÊÔ¡£È»¶øµ½ÁËSQL2005ÖÐͬÑùµÄ²Ù×÷È´±ä³ÉÁËÉú³ÉÒ»¶ÎSQLÓï·¨£¬Ã»Óе÷ÊÔ¹¦ÄÜ£¬Èç¹ûʹÓÃÁËExpress°æ±¾»á¸ü¼ÓÓôÃÆ£¬Á¬“Ö´ÐД²Ëµ¥¶¼Ã»ÓУ¬ÈçͼËùʾ£ºExpress°æ±¾ÖУ¬²Ëµ¥Öиù±¾Ã»ÓГִÐД¹¦ÄÜ¡£
ÄÇôµ÷ÊÔ¹¦Äܵ½Ê²Ã´µØ·½È¥ÁËÄØ£¿
±ð¼±£¬ÎÒÕÒµ½ÁË¡£ÔÀ´Î¢Èí°Ñµ÷ÊÔ¹¦ÄÜ·ÅÔÚÁËVS2005ÖÐÁË¡£×¢ÒâÊÇVS2005£¬²»ÊÇSQL2005£¬´ò¿ªVS2005£¬Ñ¡Ôñ¹¤¾ß¡¢ÔÙÑ¡Ôñ“Á¬½Óµ½Êý¾Ý¿â”¡£Ñ¡ÔñÕýÈ·µÄÊý¾Ý¿âÃûºÍ±íÃû£¬ÌîÈëÕýÈ·µÄµÇ½ÐÅÏ¢¾Í¿ÉÒÔÁË£¬Èçͼ£º
ÔÚ"·þÎñÆ÷×ÊÔ´¹ÜÀ퓾ͿÉÒÔ¿´µ½Ð´ÔÚÊý¾Ý¿âÖеĴ洢¹ý³ÌºÍ´¥·¢Æ÷´úÂëÁË£¬ÓÒ»÷ÏàÓ¦µÄ´æ´¢¹ý³Ì£¬±ã¿ÉÒÔ¿´¼û”µ¥²½Ö´Ðе÷ÊÔ“µÄ×ÖÑùÈçͼËùʾ£ºÈç¹ûÕâ¶Î´æ´¢¹ý³Ì¿ÉÒÔ´¥·¢”´¥·¢Æ÷“ÖдúÂ룬ÄÇô´¥·¢Æ÷µÄ´úÂëÒ²ÊÇ¿ÉÒÔµ÷ÊԵġ£
ÎÒÀ´¾Ù¸öÀý×Óµ÷ÊÔһϡ£
1¡¢ÔÚÊý¾ÝÖн¨Á¢Ò»¸ö±íAllMoney
ÁÐ ID ÀàÐÍ INT £¬¸Ã×Ö¶ÎΪ×ÔÔö×ֶΣ¬Ã¿²åÈëÒ»ÌõÊý¾Ý¾ÍÔö¼ÓÒ»¸ö¡£
ÁÐ MyMoney ÀàÐÍ Money
2¡¢ÔÚÊý¾ÝÖн¨Á¢Ò»¸ö±íLastID
ÁÐ ALLMoneyID ÀàÐÍΪINT£¬¸Ã×ֶν«Í¨¹ý´¥·¢Æð×Ô¶¯¸üÐÂÖµ£¬µ±±íAllMoneyÿ²åÈëÒ»ÁеÄʱºò£¬Õâ¸ö×ֶξÍ×Ô¶¯¸üÐÂΪAllMoneyÖеÄ×î´óIDÖµ¡£
3¡¢½¨Á¢´æ´¢¹ý³Ì¸øAllMoneyÌí¼ÓÊý¾Ý£º
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE SP_InsertMoney
@MyMoney AS MONEY
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AllMoney(MyMoney) VALUES(@MyMoney)
END
GO
4¡¢ÔÚ±íAllMoneyÖн¨Á¢´¥·¢Æ÷£¬¸üбíLastID
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER INSERT_LastID
ON AllMoney
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON
DECLARE @ID AS INT
SELE
Ïà¹ØÎĵµ£º
-----------------------------------------------------------------------------------------------------------------------
create table tb(id varchar(3) , pid varchar(3) , name varchar(10))
insert into tb values('001' , null , '¹ã¶«Ê¡')
insert into tb values('002' , '001' , '¹ãÖÝÊÐ')
insert i ......
¶à±íÁª½Ó²éѯ
Ò»¡¢¶à±íÁª½Ó²éѯµÄ·ÖÀà
¶à±íÁª½Ó²éѯʵ¼ÊÉÏÊÇͨ¹ý¸÷¸ö±íÖ®¼ä¹²Í¬ÁеĹØÁªÐÔÀ´²éѯÊý¾ÝµÄ£¬ËüÊǹØϵÊý¾Ý¿â²éѯ×îÖ÷ÒªµÄÌØÕ÷¡£
Áª½Ó²éѯ¿É·ÖΪÈý´óÀ࣬·ÖÁíΪ£º
1£® ÄÚÁª½Ó¡£
2£® ÍâÁª½Ó¡£
3£® ½»²æÁª½Ó¡£
ÄÇôÎÒÃÇÒ»ÆðÀ´¿´Ò»ÏÂÈçºÎʹÓö ......
1.ʲô½ÐSQL×¢È룿ÈçºÎ·ÀÖ¹£¿Çë¾ÙÀý˵Ã÷
´ð£ºSQL×¢ÈëÊdz£¼ûµÄÀûÓóÌÐò©¶´½øÐй¥»÷µÄ·½·¨¡£µ¼ÖÂsql×¢Èë¹¥»÷²¢·ÇϵͳÔì³ÉµÄ£¬Ö÷ÒªÊdzÌÐòÖкöÂÔÁË°²È«ÒòËØ£¬ÀûÓÃsqlÓïÑÔ©¶´»ñµÃºÏ·¨Éí·ÝµÇ½ϵͳ
ÀýÈ磺
"Select * from users where name='"+uName+"' and pwd='"+uPwd+"' " ......
·ÖÒ³²éѯµÄÔÀí£º
Õâ¸öÖ»ÄÜÓÃÔÙSql2005¼°ÒÔÉϵİ汾
DECLARE @pagenum AS INT, @pagesize AS INT
SET @pagenum = 2
SET @pagesize = 3
SELECT *
from (SELECT ROW_NUMBER()&n ......
Ò»¡¢ PL/SQLÓïÑÔ¼ò½é
(±¾½²ÒåÖ®ËùÓгÌÐò¾ùµ÷ʽͨ¹ý)
Ê×ÏÈÎÒÃÇ¿´Ò»¸ö¼òµ¥Ö®Àý×Ó,ÏÂÃæÕâ¸öÀý×ÓÊÇͳ¼Æ´Ó1ÖÁ100µÄ×ܺÍ.
declare
i number:=0; /*ÉùÃ÷±äÁ¿¾®¸ø³õÖµ*/
t number:=1;
error_message exception; /*ÉùÃ÷Ò»¸ö³ö´í´¦Àí*/
begin
......