SQL SERVER 2008 ±íÖµ²ÎÊý
/*
SQL SERVER 2008 ±íÖµ²ÎÊý
SQL SERVER ÒýÈëÁË¿¹ÒéÓÃÀ´½«Ðм¯´«Èëµ½´æ´¢¹ý³ÌºÍÓû§¶¨Ò庯ÊýµÄ±íÖµ²ÎÊý.
Õâ¸ö¹¦ÄÜ¿ÉÒÔʹ´æ´¢¹ý³ÌºÍº¯Êý¾ßÓзâ×°¶à¸öÐм¯µÄ¹¦ÄÜ,¶ø²»ÊDZØÐëÒ»ÐÐÒ»Ðеص÷
Êý¾ÝÐ޸Ĺý³ÌºÍ´©¼þ¶à¸öÊäÈë²ÎÊýÀ´ÉúÓ²µÄת»¯Îª¶àÐÐ.
ÎÒÃÇÔÚÓ¦ÓÃÖо³£Óõ½µÄ²åÈëʱ°Ñ´úÂë·â×°µ½´æ´¢¹ý³ÌÖС£
*/
CREATE DATABASE TESTDB
USE TESTDB
GO
CREATE TABLE USERINFO(USERID INT,USERNAME NVARCHAR(50))
GO
CREATE PROC USP_INSERT_USERINFO
@ID INT,
@NAME NVARCHAR(50)
AS
INSERT USERINFO
VALUES(@ID,@NAME)
GO
/*
ÉÏÃæµÄ»·¾³½¨Á¢ºÃºó£¬Èç¹ûÎÒÃÇÐèÒªÏò±íÖвåÈëÐÐÊý£¬¾ÍÐèÒªµ÷ÓôÎÕâ¸ö
´æ´¢¹ý³Ì¡£ÔÚ´ó¶àÊýÇé¿öÏÂÕâÑùµÄÇé¿öÊÇ¿ÉÒÔ½ÓÊܵģ¬Èç¹ûÄã¾³£ÐèÒªÒ»´Î²åÈë¶à
Ìõ¡£ÄÇô¾Í¿ÉÒÔÓÃÖÐÐÂÔöµÄ±íÖµ²ÎÊýÀàÐÍ£¬¿ÉÒÔ½«Òª²åÈëµÄÊý¾Ý´«Èëµ½±íÖµ²Î
ÊýÖУ¬È»ºóͨ¹ý±íÖµ²ÎÊýÒ»´ÎÐÔ²åÈëµÄ±íÖС£
ÏÂÃæÑÝʾ¸Ã²ÎÊýÀàÐÍ¡£
*/
--ҪʹÓñíÖµ²ÎÊý£¬Ê×ÏÈÒª¶¨ÒåÓû§¶¨Òå±íÊý¾ÝÀàÐÍ¡£
CREATE TYPE T_USERINFO AS TABLE
(USERID INT,
USERNAME NVARCHAR(50)
)
GO
--ÏÂÃæ¿ÉÒÔ¶ÔÉÏÃæµÄ¹ý³ÌUSP_INSERT_USERINFO½øÐÐÐ޸ġ£
CREATE PROC USP_INSERT_USERINFO_NEW
@USERINFO T_USERINFO READONLY --±ØÐëʹÓÃREADONLY Ñ¡ÏîÉùÃ÷±íÖµ²ÎÊý
AS
INSERT USERINFO
&nbs
Ïà¹ØÎĵµ£º
ÎÄÕÂÓÉÀ´£º ×î½üÐèÒª×öÕâÑùµÄ²âÊÔ:Install the products on machine which case-insensitive SQL installed.
Ëùνcase-insensitive SQL installed¡¡Ö¸ÔÚÊý¾Ý¿â°²×°Ê±Ñ¡ÔñÅÅÐò¹æÔòʱ¡¡ÐèҪѡÔñ´óСдÇø±ðµÄ¹æÔò¡£
¡¡¡¡ÅÅÐò¹æÔò¼ò½é£º
¡¡¡¡¡¡¡¡MSÊÇÕâÑùÃèÊöµÄ£º"ÔÚ Micr ......
ÔʼÊý¾Ý
TERMINAL_ID
MAXDATE
TERMINAL_ID
OCCUR_DATE_TIME
TROUBLE_CD
1
12345
20100401102754
12345
20100401102754
210
2
12345
20100401102754
12345
20100401102754
211
3
12345
20100401102754
12345
20100401102754
?09
......
declare @xml xml
set @xml = '<root/>'
select @xml
declare @value varchar(10)
set @value = 'val1'
set @xml.modify('insert <item value="{sql:variable("@value")}" /> into (/root)[1]')
select @xml
set @value = 'val2'
set @xml.modify('replace value of (/root/item/@value)[1] with "val2 ......
TOP ÔöÇ¿¹¦ÄÜ
1¡¢TOP ÔöÇ¿¡£¿ÉÒÔÖ¸¶¨Ò»¸öÊý×Ö±í´ïʽ£¬ÒÔ·µ»ØҪͨ¹ý²éѯӰÏìµÄÐÐÊý»ò°Ù·Ö±È£¬»¹¿ÉÒÔ¸ù¾ÝÇé¿öʹÓñäÁ¿»ò×Ó²éѯ¡£
¿ÉÒÔÔÚDELETE¡¢UPDATEºÍINSERT²éѯÖÐʹÓÃTOPÑ¡Ïî¡£
2¡¢¸üºÃµØÌæ»»SET ROWCOUNTÑ¡Ïʹ֮¸üΪÓÐЧ¡£
OUTPUT
1¡¢SQL Server 2005ÒýÈëÒ»¸öеÄOUTPUT×Ӿ䣬ÒÔʹÄú¿ÉÒÔ³åÐÞ¸ÄÓï¾ä(INSERT¡ ......
COUNT(*)ÓëCOUNT(COL)
ÍøÉÏËÑË÷ÁËÏ£¬·¢ÏÖ¸÷ÖÖ˵·¨¶¼ÓУº
±ÈÈçÈÏΪCOUNT(COL)±ÈCOUNT(*)¿ìµÄ£»
ÈÏΪCOUNT(*)±ÈCOUNT(COL)¿ìµÄ£»
»¹ÓÐÅóÓѺܸãЦµÄ˵µ½Õâ¸öÆäʵÊÇ¿´ÈËÆ·µÄ¡£
ÔÚ²»¼ÓWHEREÏÞÖÆÌõ¼þµÄÇé¿öÏ£¬COUNT(*)ÓëCOUNT(COL)»ù±¾¿ÉÒÔÈÏΪÊǵȼ۵ģ»
µ«ÊÇÔÚÓÐWHEREÏÞÖÆÌõ¼þµÄÇé¿öÏ£¬COUNT(*)»á±ÈCOUNT(COL)¿ì·Ç³£¶à ......