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

SQL ±êÁ¿Öµº¯ÊýµÄµ÷ÓÃ

µ÷Óà MS SQL ±êÁ¿Öµº¯Êý£¬Ó¦¸ÃÔÚº¯ÊýÇ°Ãæ¼ÓÉÏ "dbo."£¬·ñÔò»á±¨ “²»ÊÇ¿ÉÒÔʶ±ðµÄ ÄÚÖú¯ÊýÃû³Æ”´íÎó¡£ÀýÈç
    DECLARE @WhichDB TINYINT;
    SELECT @WhichDB = user_GetWhichDB(1);--¿´¿´ÊÇÄĸöÊý¾Ý¿âµÄ
=================================================
--±êÁ¿Öµº¯Êý
ALTER FUNCTION [dbo].[user_GetWhichDB]
(
    @UserId INT = 0
)
RETURNS TINYINT
WITH EXECUTE AS CALLER
AS
BEGIN
    DECLARE @WhichDB TINYINT;
    SET @WhichDB = 1;
    IF @UserId >= 115098
        SET @WhichDB = 2;
   
    RETURN (@WhichDB);
END


Ïà¹ØÎĵµ£º

SQL ServerÖеÄCTE

 1¡¢¹«Óñí±í´ïʽ (CTE) ¿ÉÒÔÈÏΪÊÇÔÚµ¥¸ö SELECT¡¢INSERT¡¢UPDATE¡¢DELETE »ò CREATE VIEW Óï¾äµÄÖ´Ðз¶Î§ÄÚ¶¨ÒåµÄÁÙʱ½á¹û¼¯¡£CTE ÓëÅÉÉú±íÀàËÆ£¬¾ßÌå±íÏÖÔÚ²»´æ´¢Îª¶ÔÏ󣬲¢ÇÒÖ»ÔÚ²éѯÆÚ¼äÓÐЧ¡£ÓëÅÉÉú±íµÄ²»Í¬Ö®´¦ÔÚÓÚ£¬CTE ¿É×ÔÒýÓ㬻¹¿ÉÔÚͬһ²éѯÖÐÒýÓöà´Î¡£
¡¡¡¡CTE ¿ÉÓÃÓÚ£º
¡¡¡¡´´½¨µÝ¹é²éѯ¡£ÓйØÏêϸР......

sqlÓï¾ä´´½¨³ÉµÇ¼

 1 windowsµÇ¼ÕË»§¿Ú£ºEXEC ap_grantlogin 'windowsÓòÃû\ÓòÕË»§'
 2 SQL µÇ¼ÕË»§:EXEC sp_addlogin 'ÕË»§Ãû','ÃÜÂë'
 3 ´´½¨Êý¾Ý¿âÓû§:exec spgrantdbaccess 'µÇ¼ÕË»§','Êý¾Ý¿âÓû§'
¶þ ¸øÊý¾Ý¿âÓû§ÊÚȨ
grant ȨÏÞ on ±íÃû to Êý¾Ý¿âÓû§ ......

sql server ÖÐɾ³ýĬÈÏÔ¼ÊøµÄͨÓÃsql½Å±¾

 ×÷Õߣº sealyu   ÈÕÆÚ£º2008-04-17
ÔÚSQL Server ÖУ¬Èç¹û¸ø±íµÄÒ»¸ö×Ö¶ÎÉèÖÃÁËĬÈÏÖµ£¬¾Í»áÔÚϵͳ±ísysobjectsÖÐÉú³ÉÒ»¸öĬÈÏÔ¼Êø¡£
Èç¹ûÏëɾ³ýÕâ¸öÉèÖÃÁËĬÈÏÖµµÄ×ֶΣ¨¼ÙÉè´Ë×Ö¶ÎÃûcolumn1£©£¬
Ö´ÐГALTER TABLE table1 DROP COLUMN column1”ʱ¾Í»á±¨´í£º
The object 'DF__xxxxxxxxxxx' ......

SQLÈÕÆÚºÍʱ¼äº¯Êý

 
--»ùÓÚʱ¼äSQLº¯Êý--
getdate() --·µ»Øµ±Ç°ÏµÍ³ÈÕÆÚºÍʱ¼ä¡£
DateAdd --ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ¡£
DATEADD ( datepart , number, date )
--Àý£ºÏòµ±ÌìµÄʱ¼äÔö¼Ó5Ìì
select dateadd(dd,5,getdate())
datediff --·µ»Ø¿çÁ½¸öÖ¸¶¨ÈÕÆÚµÄÈÕÆÚºÍʱ¼ä±ß½çÊý¡£]
---ÀýÈç
 & ......

Ô¶³Ì±¸·ÝsqlÊý¾Ý¿âµ½±¾»ú

 Ìõ¼þ£º
    ÓµÓÐsaȨÏÞ
    ¿ªÆô xp_cmdshell
·½·¨£º
 ¿ªÆô/¹Ø±Õ xp_cmdshell ±ØÐëÔÚ master  ¿âÖ´ÐÐ
EXEC sp_configure 'show advanced options', 1 
RECONFIGURE WITH OVERRIDE 
EXEC sp_configure 'xp_cmdshell', 1 
RECONFIGURE ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ