ÁÙʱ±ívs.±í±äÁ¿ÒÔ¼°ËüÃǶÔSQLServerÐÔÄܵÄÓ°Ïì
ÔÚÁÙʱ±í
create table #T (…)
ºÍ±í±äÁ¿
declare @T table (…)
Ö®¼äÖ÷ÒªÓÐ3¸öÀíÂÛÉϵIJ»Í¬¡£
µÚÒ»¸ö²»Í¬Ê¹ÊÂÎñÈÕÖ¾²»»á¼Ç¼±í±äÁ¿¡£Òò´Ë£¬ËüÃÇÍÑÀëÁËÊÂÎñ»úÖƵķ¶Î§£¬´ÓÏÂÃæµÄÀý×Ó¿ÉÏÔ¶øÒ×¼û£º
create table #T (s varchar(128))
declare @T table (s varchar(128))
insert into #T select 'old value #'
insert into @T select 'old value @'
begin transaction
update #T set s='new value #'
update @T set s='new value @'
rollback transaction
select * from #T
select * from @T
s
---------------
old value #
s
---------------
new value @
ÔÚÉùÃ÷ÁÙʱ±í#TºÍ±í±äÁ¿@TÖ®ºó£¬¸øËüÃÇ·ÖÅäÒ»¸öÏàͬµÄֵΪold value×Ö·û´®¡£È»ºó£¬¿ªÊ¼Ò»¸öÊÂÎñÈ¥¸üÐÂËüÃÇ¡£´Ëʱ£¬ËüÃǶ¼½«ÓÐеÄÏàͬµÄÖµnew value×Ö·û´®¡£µ«µ±ÊÂÎñ»Ø¹öʱ£¬ÕýÈçÄãËù¿´µ½µÄ£¬±í±äÁ¿@T±£ÁôÁËÕâ¸öÐÂÖµ¶øûÓзµ»Øold value×Ö·û´®¡£ÕâÊÇÒòΪ¼´Ê¹±í±äÁ¿ÔÚÊÂÎñÄÚ±»¸üÐÂÁË£¬Ëü±¾Éí²»ÊÇÊÂÎñµÄÒ»²¿·Ö¡£
µÚ¶þ¸öÖ÷ÒªµÄ²»Í¬ÊÇÈκÎÒ»¸öʹÓÃÁÙʱ±íµÄ´æ´¢¹ý³Ì¶¼²»»á±»Ô¤±àÒ룬Ȼ¶øʹÓñí±äÁ¿µÄ´æ´¢¹ý³ÌµÄÖ´Ðмƻ®¿ÉÒÔÔ¤ÏȾ²Ì¬µÄ±àÒë¡£Ô¤±àÒëÒ»¸ö½Å±¾µÄÖ÷ÒªºÃ´¦ÔÚÓÚ¼Ó¿ìÁËÖ´ÐеÄËٶȡ£Õâ¸öºÃ´¦¶ÔÓÚ³¤µÄ´æ´¢¹ý³Ì¸ü¼ÓÏÔÖø£¬ÒòΪ¶ÔËüÀ´ËµÖØбàÒë´ú¼ÛÌ«¸ß¡£
×îºó£¬±í±äÁ¿½ö´æÔÚÓÚÄÇЩ±äÁ¿ÄÜ´æÔÚµÄÏàͬ·¶Î§ÄÚ¡£ºÍÁÙʱ±íÏà·´£¬ËüÃÇÔÚÄÚ²¿´æ´¢¹ý³ÌºÍexec£¨string£©Óï¾äÀïÊDz»¿É¼ûµÄ¡£ËüÃÇÒ²²»ÄÜÔÚinsert/execÓï¾äÀïʹÓá£
ÐÔÄܱȽÏ
Ê×ÏÈ£¬×¼±¸Ò»¸öÓÐ100Íò¼Ç¼µÄ²âÊÔ±í£º
create table NUM (n int primary key, s varchar(128))
GO
set nocount on
declare @n int
set @n=1000000
while @n>0 begin
insert into NUM
select @n,'Value: '+convert(varchar,@n)
set @n=@n-1
end
GO
×¼±¸²âÊÔ´æ´¢¹ý³ÌT1£º
create procedure T1
@total int
as
create table #T (n int, s varchar(128))
insert into #T select n,s from NUM
where n%100>0 and n<=@total
declare @res varchar(128)
select @res=max(s) from NUM
where n<=@total and
Ïà¹ØÎĵµ£º
DATEDIFF(datepart, startdate, enddate)
Datepart Abbreviations
year yy, yyyy
quarter qq, q
month mm, m
......
µÚÒ»ÖÖ JavaScriptÁ¬½ÓÊý¾Ý¿â£º
<mce:script language="JavaScript"><!--
// ´´½¨Êý¾Ý¿â¶ÔÏó
var objdbConn = new ActiveXObject("ADODB.Connection");
// DSN×Ö·û´®
var strdsn = "Driver={SQL Server};SERVER=192.168.0.210;UID=xhb;PWD=xhb;DATABASE=books";
// ´ò¿ªÊý¾ÝÔ´
objdbConn.Open(strdsn);
// ......
/******************************
ϵͳº¯Êý
******************************/
--convert ÓÃÀ´×ª±äÊý¾ÝÀàÐÍ
--convert (data_type[(length)], expression [, style])
select convert(int,convert(varchar(5),12345)+'678')+1 --·µ»Ø12345679
--cast Ò²ÊÇÓÃÀ´×ª»»Êý¾ÝÀàÐÍ
--cast(expression as data_type[(l ......
sqlServer£º
Ò»´Î²éѯ£¬Êý¾Ý¿âÖ»·µ»ØÒ»Ò³µÄÊý¾Ý¡£¶ø²»ÊÇÈ¡³öËùÓеÄÊý¾Ý¡£
pagesize£º ÿҳÏÔʾ¼Ç¼Êý
cureentpage£ºµ±Ç°Ò³Êý
select * from ( select TOP pagesize * from ( SELECT TOP pagesize*cureentpage * from my_table ORDER BY id ASC ) as amyTable OR ......
ÃüÃû¹ý³ÌÖÐÈçÓÐÏÖ´æµÄËõд£¬ÔòʹÓøÃËõд£¬ÈçÎÞ£¬Ò»Âɲ»µÃËõд£¬Àý£ºISBN
Êý¾Ý¿â£ºÓÃÒ»¸ö»òÈý¸öÒÔÏÂÓ¢Îĵ¥´Ê×é³É£¬µ¥´ÊÊ××Öĸ´óд£¬È磺DepartmentManage£»
±íÃû£ºÊ¹ÓÃÃû´ÊÐÔÖʵĵ¥´ÊÈ«Æ´±íʾ£¬¸÷µ¥´ÊÊ××Öĸ´óд£¬ ʹÓø´ÊýÐÎʽ£¬È磺Books
Èç¹û¸Ã±íÓÃÓÚ±íÃ÷ÁíÍâÁ½±íÖÐ×ֶμäµÄ¹Øϵ£¬Óõ ......