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

SQL UpdateÓï¾äµÄÖ´ÐÐ˳Ðò

Ö´ÐÐ˳Ðò:´Ó×óµ½ÓÒ,±äÁ¿ÓÅÏÈ,ÖðÐиüÐÂ
 Õª×ÔCSDNµÄÀý×Ó(http://topic.csdn.net/u/20091030/16/7fd75fa6-bdb9-4516-9b27-48aef69703ba.html
http://topic.csdn.net/u/20090904/16/e5dad9c7-fb59-41b9-b28d-e3b71c3e8420.html)
1.±äÁ¿ÓÅÏÈ
create table #t (field1 varchar(10),field2 varchar(10))
insert #t select 'a','b'
declare @str varchar(10)
set @str='Test'
update #t set Field1=@str,@str=Field2,Field2=Field1
select * from #t
drop table #t
/*field1     field2
---------- ----------
b          a*/
2.Ö𲽸üÐÂ
if OBJECT_ID('ta') is not null drop table ta
create table ta(empNo varchar(8) ,empName varchar(20),nIndex int)  --drop table ta
insert into ta
select 'A0001','張Èý',null
union
select 'A0002','ÀîËÄ',null
union
select 'A0003','Íõ¶þ',null
union
select 'A0004','ôôÁù',null
declare @tmpIndex int
set @tmpIndex=0
update ta set nIndex=@tmpIndex,@tmpIndex=@tmpIndex+1
select * from ta
/*
empNo    empName    nIndex
A0001    張Èý    1
A0002    ÀîËÄ    2
A0003    Íõ¶þ    3
A0004    ôôÁù    4
*/
(1 ÐÐÊÜÓ°Ïì)*/
3.×Ö¶ÎÖ®¼ä, ²¢ÐÐÖ´ÐÐ
create table #t (field1 varchar(10),field2 varchar(10))
insert #t select 'a','b'
declare @str varchar(10)
update #t set Field1=Field2,Field2=Field1
select * from #t
/*
field1     field2
---------- ----------
b          a
*/
1£¬ ÏȱäÁ¿ÔÙ×Ö¶Î
2£¬ ±äÁ¿Ö®¼ä, ´Ó×óµ½ÓÒ
3£¬ ×Ö¶ÎÖ®¼ä, ²¢ÐÐÖ´ÐÐ


Ïà¹ØÎĵµ£º

[ת]SQL½ØÈ¡×Ö·û´®

SUBSTRING
·µ»Ø×Ö·û¡¢binary¡¢text      »ò      image      ±í´ïʽµÄÒ»²¿·Ö¡£ÓйؿÉÓë¸Ãº¯ÊýÒ»ÆðʹÓõÄÓÐЧ      Microsoft®      SQL      Server ......

SQL ALTER TABLE Óï¾ä

³ö´¦£ºhttp://www.w3school.com.cn/sql/sql_alter.asp ALTER TABLE Óï¾ä ALTER TABLE Óï¾äÓÃÓÚÔÚÒÑÓеıíÖÐÌí¼Ó¡¢Ð޸Ļòɾ³ýÁС£ SQL ALTER TABLE Óï·¨ ÈçÐèÔÚ±íÖÐÌí¼ÓÁУ¬ÇëʹÓÃÏÂÁÐÓï·¨: ALTER TABLE table_name
ADD column_name datatype
Ҫɾ³ý±íÖеÄÁУ¬ÇëʹÓÃÏÂÁÐÓï·¨£º
ALTER TABLE table_name
DROP COLUM ......

¹ØÓÚsqlµÄÁ´½Ó²éѯ


Ê×Ïȸø³öÁ½ÕŲâÊÔ±í
a(aid int, adata varchar(20))            b(bid int, bdata varchar(20))
1.join Óë inner join
Ö´ÐÐÈçÏÂÓï¾ä£º
select * from a join b on a.aid = b.bid;
ÎÒÃÇ»áµÃµ½ÈçϵĽá¹û£º
       AID ADAT ......

sqlÖ®×óÁ¬½Ó¡¢ÓÒÁ¬½Ó¡¢È«Á¬½Ó

ÎÒÃǽéÉÜÁ˱íÁ¬½Ó£¬¸üÈ·ÇеÄ˵ÊÇinner joins內Á¬½Ó¡£內Á¬½Ó½öÑ¡³öÁ½ÕűíÖл¥ÏàÆ¥ÅäµÄ¼Ç¼£®Òò´Ë£¬Õâ»áµ¼ÖÂÓÐʱÎÒÃÇÐèÒªµÄ¼Ç¼ûÓаüº¬½øÀ´¡£
Ϊ¸üºÃµÄÀí½âÕâ¸ö¸ÅÄÎÒÃǽéÉÜÁ½¸ö±í×÷ÑÝʾ¡£ËÕ¸ñÀ¼Òé»áÖеÄÕþµ³±í(party)ºÍÒéÔ±±í(msp)¡£
 
party(Code,Name,Leader)
Code: Õþµ³´úÂë
Name: Õþµ³Ãû³Æ
Le ......

SQlµÄexecute Óësp_executesql¡¡

SQLÓï¾äÀàËÆstring.Format()×é×°±äÁ¿µÄʹÓá£
Ò»°ãÀ´Ëµ£¬ÎÒÃÇ»áÔÚ³ÌÐòÔËÐÐÆڼ佫ËùÒªÔËÐеÄÃüÁîÓï¾ä×éºÏ³ÉÒ»¸ö×Ö·û´®£¬È»ºóʹÓÃEXECUTEÃüÁî»òϵͳ´æ´¢¹ý³Ì
@0sp_executesqlÀ´ÔËÐС£½ñÌ죬ÎÒÃǽ«À´Ïêϸ̽ÌÖÕâÁ½ÖÖ·½·¨¸÷×ÔµÄÓÅÁӵ㡣
(Ò») ʹÓÃEXECUTEÃüÁîÔËÐÐÃüÁî×Ö·û´®
ҪʹÓÃEXECUTEÃüÁîÀ´ÔËÐÐÒ»¸öÃüÁî×Ö·û´®µÄÓï·¨ÈçÏ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ