🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.database
Article #930

Learn Note:SQL Server 2008��2��-Transact-sql��ǿ�

#930
From: Galaxy��VOLUNTEERS
Date: Sun, 10 Aug 2008 12:40
72 lines
4250 bytes
2008/7/15
Learn Note:SQL Server 2008��2��-Transact-sql��ǿ��
 
1.���������븳ֵ
1.1 ������Ҫ�鷳��������Declare�ٸ�ֵSet������ֱ��������������ͬ��ͬʱ������
����ֵ��
Declare 
 @someIntVal INT=1, 
 @someStringVal varchar(100)='One'
1.2 ������ʾ
��VS���ܺ��������ܻ�������ʾ
1.3 +=��-= / *= / ^= / �ȵȣ�
Set @n +=1
���ѣ���Ȼ��ȷ�Ƿ���ܶ��ˣ����㲻ȷ���ı��ʽ���Dz�Ҫ�á�����Set @a *=@a+=6
֮��Ͳ�����ʹ�á�
2.�����
��ǰ���Ҫ����ܶ�����ݵĻ�������ɵ�������в���-____-b��
insert into testtbl(col1,col2) values(0,1)
insert into testtbl(col1,col2) values(1,2)
��Щ��ϲ��������룺
insert into testtbl(col1,col2)
 select 0,1 union all
 select 1,2
��ϰ�����ֲ��뷽���������ң����˿�������ı��һ������0.5�롣����
���ڵ��·�����
insert into testtbl(col1,col2)
      values 
 (0,1),
 (1,2)
�����˺ܶ��������������Щ������������Ǯ�ij���Ա�᲻ˬ����
3.MERGE/When
���Ը��Դ���Դ��Ŀ�����Դ��ƥ�����������Ŀ�����Դ
���԰�ĸ�ʽ���£�
Merge <target_table>
using <source_table>
on <search_condition>
[When matched [and <search_condition>]
 then {update...|delete}]
[When target not matched [and <search_condition>]
 then insert]
[When source not matched [and <search_condition>]
 then {update...|delete}]
ͨ��ʹ��[and <search_condition>]��������Merge��Ч��
�������ʽ�л��õ���when���ʽ�����������¼��������
when matched
when [target] not matched
when source not matched
4.�û��Զ������Ͳ���
�û������Զ�������Ϊ������stored procedure�����û��Զ��庯��ء�
��ʽ���£�
Declare @newcustomer table
(
[customerid] int NULL,
[Name] varchar(100), not NULL,
[companyname] nvarchar(128) NULL
)
Ȼ��Ϳ�����stored procedure��ʹ��Merge��ʹ�øò�����
����Զ�̿ͻ���call���߲���������������߼���Ϊ���ӵ�����£�����ʹ�ñ�����
�������������벢���߼������ӵ�����¿���ʹ��Bulk insert
��󲹳�һ������ǰ����ôʹ�õĹؼ��֣�With
��BOL�е���ĿΪ��WITH common_table_expression 
����Ϊ����һ����ʱ���CTE����05��ʼ�еĹ��ܣ��൱�ڸ߰汾����ʱ�?������
������ݿ��ķ�ҳ������ɲμ�http://tech.it168.com/db/s/2007-05-25/200705251
247531.shtml
--
I thought what I'd do was, I'd pretend I was one of those deaf-mutes
Or should I?

You know what I��d like to be? I mean if I had my goddam choice, I��d just be
the catcher in the rye and all.

�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 58.35.146.84]
Technical Details
Message-ID: <4bOdEX$aih@bbs.sjtu.edu.cn>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.neu.edu.cn!news.shec6.edu.cn!SJTU

Show Full Headers
Complete Article Headers
X-Google-Thread: 101948,e9c631616cbd4680,start
X-Google-Attributes: gid101948,domainid0,public,usenet
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.neu.edu.cn!news.shec6.edu.cn!SJTU
From: Dem.bbs@bbs.sjtu.edu.cn (Galaxy��VOLUNTEERS)
Newsgroups: cn.bbs.comp.database
Subject: Learn Note:SQL Server 2008��2��-Transact-sql��ǿ�
Date: 10 Aug 2008 12:40:44 GMT
Organization: ��ˮ˼Դ
Message-ID: <4bOdEX$aih@bbs.sjtu.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: database/M.1218372033.A
Lines: 71