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

SQL´æ´¢¹ý³ÌʵÀý


Àý1 ´«ÈëÒ»¸ö²ÎÊý@username,ÅжÏÓû§ÊÇ·ñ´æÔÚ
-------------------------------------------------------------------------------
CREATE PROC IsExistUser
(
@username varchar(20),
@IsExistTheUser varchar(25) OUTPUT--Êä³ö²ÎÊý
)
as
SELECT @IsExistTheUser = count(username)
from users
WHERE username = @username
GO
Àý2 ´æ´¢¹ý³Ì½áºÏÊÂÎñµÄÒ»¸öÀý×Ó£ºÌí¼ÓÓû§£¬Éæ¼°µ½Á½¸ö±í£¬Ò»¸öÓû§×ÊÁÏ±í£¬Ò»¸öÃÜÂë±í£º
Ôö¼ÓÓû§
-------------------------------------------------------------------------------
create procedure AddUser
(
@username varchar(20),--̞
@passwords varchar(18),--ÃÜÂë
@email varchar(100),--ÓÊÏä
@qq varchar(11),--QQºÅÂë
@imageid int--Í·Ïñ
)
as
-- ÉèÖÃNOCOUNTΪON£¬Ê¹²»ÔÙ·µ»Øͳ¼ÆÐÅÏ¢£¨´æ´¢¹ý³ÌÖаüº¬µÄһЩÓï¾ä²¢²»·µ»ØÐí¶àʵ¼ÊµÄÊý¾Ý£¬Ôò¸ÃÉèÖÃÓÉÓÚ´óÁ¿¼õÉÙÁËÍøÂçÁ÷Á¿£¬Òò´Ë¿ÉÏÔÖøÌá¸ßÐÔÄÜ¡££©
SET NOCOUNT ON
DECLARE @CurrentError int
-- ´´½¨ÊÂÎñ, ²åÈëÊý¾Ýµ½2¸ö±í
BEGIN TRANSACTION
-- ´´½¨Óû§ÐÅÏ¢
INSERT INTO users (username, email, qq, imageid)
VALUES (@username, @email, @qq, @imageid)
select @CurrentError = @@Error
IF @CurrentError != 0
BEGIN
GOTO ERROR_HANDLER
END
-- ´´½¨Óû§ÃÜÂë
INSERT INTO Signon (username, [password])
VALUES (@username, @passwords)
select @CurrentError = @@Error
IF @CurrentError != 0
BEGIN
GOTO ERROR_HANDLER
END
-- ½áÊøÊÂÎñ
COMMIT TRANSACTION
-- »Ö¸´NOCOUNTÉèÖÃΪOFF
SET NOCOUNT OFF
-- ·µ»Ø0±íʾ³É¹¦£¬ÆäËûÔòΪʧ°Ü
RETURN 0
-- ´íÎó´¦Àí
ERROR_HANDLER:
ROLLBACK TRANSACTION
SET NOCOUNT OFF
RETURN @CurrentError
GO


Ïà¹ØÎĵµ£º

MySQLÖÐÓÃsqlÓï¾ä²åÈëʱÆÚ

mysql> create table testdate(
         -> id int not null auto_increment primary key,
         -> time date);
Query OK, 0 rows affected (0.30 sec)
mysql> insert into testdate(time) values('2010-4-23');
Q ......

sql²Ù×÷ÊÖ²á

ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ 
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE) 
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT) 
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CR ......

Oracle PL/SQLÖÐÈçºÎʹÓÃ%TYPEºÍ%ROWTYPE

¡¡
¡¡¡¡1. ʹÓÃ%TYPE
¡¡¡¡ÔÚÐí¶àÇé¿öÏ£¬PL/SQL±äÁ¿¿ÉÒÔÓÃÀ´´æ´¢ÔÚÊý¾Ý¿â±íÖеÄÊý¾Ý¡£ÔÚÕâÖÖÇé¿öÏ£¬±äÁ¿Ó¦¸ÃÓµÓÐÓë±íÁÐÏàͬµÄÀàÐÍ¡£ÀýÈ磬students±íµÄfirst_nameÁеÄÀàÐÍΪVARCHAR2(20),ÎÒÃÇ¿ÉÒÔ°´ÕÕÏÂÊö·½Ê½ÉùÃ÷Ò»¸ö±äÁ¿£º
¡¡¡¡DECLARE
¡¡¡¡ v_FirstName VARCHAR2(20);
¡¡
¡¡µ«ÊÇÈç¹ûfirst_nameÁеĶ¨Òå¸Ä±äÁ ......

SQL DateTime²éѯÓë¸ñʽ

select * from orders where month(orderdate)= (select month(orderdate) from orders where orderid=10248)
1.Ò»¸öÔµÚÒ»ÌìµÄ
Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
2.±¾ÖܵÄÐÇÆÚÒ»
Select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)
3.Ò»ÄêµÄµÚÒ»Ìì
Select DATEADD(yy, DATEDIFF(yy,0,getdate()), 0) ......

mysql+phpÎÞ·¨Á¬½Ósql£¨Òѽâ¾ö£©

¸ãÁ˺ܾᣡ£ÖÕÓÚ·¢ÏÖÔ­À´ÊÇȨÏÞÎÊÌâ¡£¡£
2ÐÐÃüÁî¸ã¶¨
grant all privileges on rogue.* to admin@localhost identified by 'admin' with grant option
grant all privileges on rogue.* to admin@'%' identified by 'admin' with grant option
¾­µäÁË¡£¡£¡£
ħÁ¦Ë½·þÍøÒ³¶Ë¸ã¶¨¿©~~ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ