Ò»¡¢¼òµ¥²éѯ
¡¡¡¡ ¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣
ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ
±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
SELECT nickname,email
from testtable WHERE name='ÕÅÈý'
(Ò»)Ñ¡ÔñÁбí
¡¡¡¡Ñ¡ÔñÁбí(select_list)Ö¸³öËù²éѯÁУ¬Ëü¿ÉÒÔÊÇÒ»×éÁÐÃûÁÐ±í¡¢ÐǺš¢±í´ïʽ¡¢±äÁ¿(°üÀ¨¾Ö²¿±ä Á¿ºÍÈ«¾Ö±äÁ¿)µÈ¹¹³É¡£
¡¡¡¡ 1¡¢Ñ¡ÔñËùÓÐÁÐ ÀýÈ磬ÏÂÃæÓï¾äÏÔʾtesttable±íÖÐËùÓÐÁеÄÊý¾Ý£º SELECT * from testtable
¡¡¡¡ 2¡¢Ñ¡Ôñ²¿·ÖÁв¢Ö¸¶¨ËüÃǵÄÏÔʾ´ÎÐò ²éѯ½á¹û¼¯ºÏÖÐÊý¾ÝµÄÅÅÁÐ˳ÐòÓëÑ¡ÔñÁбíÖÐËùÖ¸¶¨µÄÁÐÃûÅÅÁÐ˳ÐòÏàͬ¡£
ÀýÈ磺 SELECT nickname,email from testtable
¡¡¡¡ 3¡¢¸ü¸ÄÁбêÌâ ÔÚÑ¡ÔñÁбíÖУ¬¿ÉÖØÐÂÖ¸¶¨ÁбêÌâ¡£¶¨Òå¸ñʽΪ£º ÁбêÌâ=ÁÐÃû ÁÐÃû ÁбêÌâ Èç¹ûÖ¸¶¨µÄÁбêÌâ²»ÊDZê×¼µÄ±êʶ·û¸ñʽʱ£¬Ó¦Ê¹ÓÃÒýºÅ¶¨½ç·û¡£
ÀýÈ磬ÏÂÁÐÓï¾äʹÓúº×ÖÏÔʾÁÐ ±êÌ⣺ SELECT êdzÆ=nickname,µç×ÓÓʼþ=email from testtable
¡¡¡¡ 4¡¢É¾³ýÖظ´ÐÐ SELECTÓï¾äÖÐʹÓÃALL»òDISTINCTÑ¡ÏîÀ´ÏÔʾ±íÖзûºÏÌõ¼þµÄËùÓÐÐлòɾ³ýÆäÖÐÖظ´µÄÊý¾ÝÐУ¬Ä¬ÈÏ ......
ÔÚ·Ö×éÅÅÐò¹ý³ÌÖÐÐèҪн¨ÅÅÐòÁУ¬°´Ìõ¼þ:(ÎïÁÏ·ÖÀà+¿Í»§Ãû³Æ) ½øÐзÖ×é»ã×Ü È»ºó¾Í¸ù¾Ý¸ÃÌõ¼þ½øÐÐÅÅÐò
1.ÐèҪƴ´ÕÁ½ÁÐ ×÷ΪÅÅÐòÁÐ,ÈçÐè¼ÓÈëÌØÊâ×Ö·û.¾Í»á±¨´í.
ÒòΪ±¾Éí¸Ä×ֶξÍÊÇvarcharÀàÐÍ ÐèÒª½«charÀàÐÍ'_' ת»»³Évarchar
2.Æ´´Õ¹ý³ÌÖÐÓпոñÐèҪȥ¿Õ¸ñ
e.g£ºselect (trim(ÎïÁÏ·ÖÀà)+to_char('_')+¿Í»§Ãû³Æ) from tableName ......
QZone Editor
.dump{}
//TODO ÓòÃû
if (location.hash) {
document.domain=location.hash.substr(1);
}
//parent.qZEditor.callback();
function init(){
//»ñÈ¡±à¼Æ÷Ãæ°åID
var pid = frameElement.panelID;
//»ñÈ¡±à¼Æ÷Ãæ°å¶ÔÏó
var panel = parent.QZFL.editor.editPanel.get(pid);
panel["html"]._enableEditMode();
}
¡¡¡¡ÔÚsql2005ÖУ¬´æ´¢¹ý³Ì¹¦Äܷdz£Ç¿´ó£¬ÈçºÎÔÚC#Öе÷ÓÃÄØ£¬ÏÂÃæ¾ÍÒÔʾÀý˵Ã÷£º
¡¡¡¡Ê×ÏÈÔÚÊý¾Ý¿âÖд´½¨´æ´¢¹ý³ÌXSPTest
¡¡¡¡CREATE PROCEDURE dbo.XSPTest
¡¡¡¡¡¡¡¡@In As nvarchar(16),
¡¡¡¡¡¡¡¡@Out As int OUTPUT
¡¡¡¡As
¡¡¡¡¡¡¡¡-- deal with @In
¡¡¡¡¡¡¡¡Set @Out = 1;
¡¡¡¡¡¡¡¡Select 2 As SValue;
¡¡¡¡¡¡¡¡RETURN 0;
¡¡¡¡ÉÏÃæµÄ´æ´¢¹ý³ÌÐèÒªÒ»¸öÊäÈë²ÎÊý£¬Ò»¸öÊä³ö²ÎÊý£¬·µ»ØÒ»¸öÖµ£¬²¢ÇÒselectÒ»¸ö¡£ÏÂÃæ¾Í·Ö±ð˵Ã÷һϣº
¡¡¡¡ SqlCommand cmdCommit = new
SqlCommand("XSPTest", myConnect)
c ......
QZone Editor
.dump{}
//TODO ÓòÃû
if (location.hash) {
document.domain=location.hash.substr(1);
}
//parent.qZEditor.callback();
function init(){
//»ñÈ¡±à¼Æ÷Ãæ°åID
var pid = frameElement.panelID;
//»ñÈ¡±à¼Æ÷Ãæ°å¶ÔÏó
var panel = parent.QZFL.editor.editPanel.get(pid);
panel["html"]._enableEditMode();
}
¡¡¡¡ÔÚsql2005ÖУ¬´æ´¢¹ý³Ì¹¦Äܷdz£Ç¿´ó£¬ÈçºÎÔÚC#Öе÷ÓÃÄØ£¬ÏÂÃæ¾ÍÒÔʾÀý˵Ã÷£º
¡¡¡¡Ê×ÏÈÔÚÊý¾Ý¿âÖд´½¨´æ´¢¹ý³ÌXSPTest
¡¡¡¡CREATE PROCEDURE dbo.XSPTest
¡¡¡¡¡¡¡¡@In As nvarchar(16),
¡¡¡¡¡¡¡¡@Out As int OUTPUT
¡¡¡¡As
¡¡¡¡¡¡¡¡-- deal with @In
¡¡¡¡¡¡¡¡Set @Out = 1;
¡¡¡¡¡¡¡¡Select 2 As SValue;
¡¡¡¡¡¡¡¡RETURN 0;
¡¡¡¡ÉÏÃæµÄ´æ´¢¹ý³ÌÐèÒªÒ»¸öÊäÈë²ÎÊý£¬Ò»¸öÊä³ö²ÎÊý£¬·µ»ØÒ»¸öÖµ£¬²¢ÇÒselectÒ»¸ö¡£ÏÂÃæ¾Í·Ö±ð˵Ã÷һϣº
¡¡¡¡ SqlCommand cmdCommit = new
SqlCommand("XSPTest", myConnect)
c ......
BEGIN TRANSACTION--¿ªÊ¼ÊÂÎñ
DECLARE @errorSun INT --¶¨Òå´íÎó¼ÆÊýÆ÷
SET @errorSun=0 --û´íΪ0
UPDATE a SET id=232 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
UPDATE aa SET id=2 WHERE a=1 --ÊÂÎñ²Ù×÷SQLÓï¾ä
SET @errorSun=@errorSun+@@ERROR --ÀÛ¼ÆÊÇ·ñÓдí
IF @errorSun<>0
BEGIN
PRINT 'ÓдíÎ󣬻عö'
ROLLBACK TRANSACTION--ÊÂÎñ»Ø¹öÓï¾ä
END
ELSE
BEGIN
PRINT '³É¹¦£¬Ìá½»'
COMMIT TRANSACTION--ÊÂÎñÌá½»Óï¾ä
END
1.ʲôÊÇÊÂÎñ£ºÊÂÎñÊÇÒ»¸ö²»¿É·Ö¸îµÄ¹¤×÷Âß¼µ¥Ôª£¬ÔÚÊý¾Ý¿âϵͳÉÏÖ´Ðв¢·¢²Ù×÷ʱÊÂÎñÊÇ×öΪ×îСµÄ¿ØÖƵ¥ÔªÀ´Ê¹Óõġ£Ëû°üº¬µÄËùÓÐÊý¾Ý¿â²Ù×÷ÃüÁî×÷Ϊһ¸öÕûÌåÒ»ÆðÏòϵÌá½»»ò³·Ïû£¬ÕâÒ»×éÊý¾Ý¿â²Ù×÷ÃüÁîҪô¶¼Ö´ÐУ¬ÒªÃ´¶¼²»Ö´ÐС£
2.ÊÂÎñµÄÓï¾ä
¡¡¿ªÊ¼ÊÂÎBEGIN TRANSACTION
¡¡Ìá½»ÊÂÎCOMMIT TRANSACTION
¡¡»Ø¹öÊÂÎñ£ºROLLBACK TRANSACTION
3.ÊÂÎñµÄ4¸öÊôÐÔ
¢ÙÔ×ÓÐÔ(Atomicity)£ºÊÂÎñÖеÄËùÓÐÔªËØ×÷Ϊһ¸öÕûÌåÌá½»»ò»Ø¹ö£¬ÊÂÎñµÄ¸öÔªËØÊDz»¿É·ÖµÄ£¬ÊÂÎñÊÇÒ»¸öÍêÕû²Ù×÷¡£
¢ÚÒ»ÖÂÐÔ(Consistemcy)£ºÊÂÎïÍê³Éʱ£¬Êý¾Ý±ØÐëÊÇÒ»Ö ......
if exists(select 1 from sysobjects where name='char_index')
drop function char_index
create function char_index(@string varchar(8000),@char varchar(10),@index smallint)
--@string:´ý²éÕÒ×Ö·û´®£¬@index:²éÕÒλÖÃ
returns smallint
as
begin
declare
@i tinyint,--µ±Ç°ÕÒµ½µÚ@i¸ö
@position tinyint--ËùÔÚλÖÃ
set @position=@index;
set @i=0;
while charindex(@char,@string,@position)>0
begin
set @position=charindex(@char,@string,@position)+1;
set @i=@i+1;
if @i=@index
begin
return @position-1;
end
end
return 0;--0±íʾδÕÒµ½
end
select dbo.char_index('sdf_dsf_dfgdg_ertr_erte','f_',2)
--ÈçºÎ²éÕÒij¸ö×Ö·û´®µÚN´Î³öÏÖµÄλÖÃ,
--±ÈÈç:×Ö·û´®"sdf_dsf_dfgdg_ertr_erte",Òª²éÕÒ"f_"µÚ¶þ´Î³öÏÖµÄλÖÃ
if object_id('f_findstr') is not null
drop function f_findstr
go
create function f_findstr(@s varchar(800 ......
CREATE Table <±íÃû>
£¨[<ÁÐÃû1>] ÀàÐÍ (³¤¶È) [ȱʡֵ][Áм¶Ô¼Êø]
[£¬<ÁÐÃû2> Êý¾ÝÀàÐÍ[ȱʡֵ][Áм¶Ô¼Êø]]….
[£¬UNIQUE£¨ÁÐÃû[£¬ÁÐÃû]….£©]
[£¬PRIMARY KEY£¨ÁÐÃû[£¬ÁÐÃû]…£©]
[£¬FOREIGN KEY £¨ÁÐÃû[£¬ÁÐÃû]…£©
REFERENCES ±íÃû£¨ÁÐÃû[£¬ÁÐÃû]…£©]
[£¬CKECK (Ìõ¼þ)] )
¹¦ÄÜ£º
½¨Á¢Ò»¸öÒÔ<±íÃû>ΪÃûµÄ±í¡£
/*´´½¨½èÊ黹ÊéÊý¾Ý¿â*/
create database ½èÊ黹ÊéÐÅÏ¢
on
( name = N'½èÊ黹ÊéÐÅÏ¢Data',
filename = N'D:\½èÊ黹ÊéÐÅÏ¢.mdf',
size = 20Mb,
maxsize = 40Mb,
filegrowth = 10Mb
)
log on
( name = N'½èÊ黹ÊéÐÅÏ¢_Log',
filename = N'D:\½èÊ黹ÊéÐÅÏ¢_Log.ldf',
size = 20Mb,
maxsize = 35Mb,
filegrowth = 10Mb
)
collate SQL_Latin1_General_CP1_CI_AS
go
/*´´½¨Êý¾Ý±í*/
use ½èÊ黹ÊéÐÅÏ¢
go
create table dbo.ͼÊé
(
ͼÊé±àºÅ int identity(1,1) not null ,
ͼÊé ......