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

Ö´ÐдøǶÈë²ÎÊýµÄsql——sp_executesql

ͨ³£Ö´ÐÐsqlÓï¾ä£¬´ó¼ÒÓõĶ¼ÊÇexec£¬exec¹¦ÄÜÇ¿´ó£¬µ«²»Ö§³ÖǶÈë²ÎÊý£¬sp_executesql½â¾öÁËÕâ¸öÎÊÌâ¡£³­Ò»¶Îsqlserver°ïÖú£º
sp_executesql
Ö´ÐпÉÒÔ¶à´ÎÖØÓûò¶¯Ì¬Éú³ÉµÄ Transact-SQL Óï¾ä»òÅú´¦Àí¡£Transact-SQL Óï¾ä»òÅú´¦Àí¿ÉÒÔ°üº¬Ç¶Èë²ÎÊý¡£
Óï·¨
sp_executesql
[@stmt
=
] stmt
[
    
{,
[@params
=
] N'@
parameter_name  data_type
[,
...n
]'
}
    {,
[@
param1
=
] '
value1
'
[,
...n
] }
]
²ÎÊý
[@stmt
=
] stmt
°üº¬ Transact-SQL Óï¾ä»òÅú´¦ÀíµÄ Unicode ×Ö·û´®£¬stmt
±ØÐëÊÇ¿ÉÒÔÒþʽת»»Îª ntext
µÄ
Unicode ³£Á¿»ò±äÁ¿¡£²»ÔÊÐíʹÓøü¸´Ô Unicode ±í´ïʽ£¨ÀýÈçʹÓà +
ÔËËã·û´®ÁªÁ½¸ö×Ö·û´®£©¡£²»ÔÊÐíʹÓÃ×Ö·û³£Á¿¡£Èç¹ûÖ¸¶¨³£Á¿£¬Ôò±ØÐëʹÓà N ×÷Ϊǰ׺¡£ÀýÈ磬Unicode ³£Á¿ N'sp_who'
ÊÇÓÐЧµÄ£¬µ«ÊÇ×Ö·û³£Á¿ 'sp_who' ÔòÎÞЧ¡£×Ö·û´®µÄ´óС½öÊÜ¿ÉÓÃÊý¾Ý¿â·þÎñÆ÷ÄÚ´æÏÞÖÆ¡£
stmt
¿ÉÒÔ°üº¬Óë±äÁ¿ÃûÐÎʽÏàͬµÄ²ÎÊý£¬ÀýÈ磺
N'SELECT * from Employees WHERE EmployeeID = @IDParameter'
stmt
Öаüº¬µÄÿ¸ö²ÎÊýÔÚ @params
²ÎÊý¶¨ÒåÁбíºÍ²ÎÊýÖµÁбíÖоù±ØÐëÓжÔÓ¦Ïî¡£
[@params
=
] N'@
parameter_name  data_type
[,
...n
]'
×Ö·û´®£¬ÆäÖаüº¬ÒÑǶÈëµ½ stmt
ÖеÄËùÓвÎÊýµÄ¶¨Òå¡£¸Ã×Ö·û´®±ØÐëÊÇ¿ÉÒÔÒþʽת»»Îª ntext
µÄ Unicode ³£Á¿»ò±äÁ¿¡£Ã¿¸ö²ÎÊý¶¨Òå¾ùÓɲÎÊýÃûºÍÊý¾ÝÀàÐÍ×é³É¡£n
ÊDZíÃ÷¸½¼Ó²ÎÊý¶¨ÒåµÄռλ·û¡£stmt
ÖÐÖ¸¶¨µÄÿ¸ö²ÎÊý¶¼±ØÐëÔÚ @params
Öж¨Òå¡£Èç¹û stmt
ÖÐµÄ Transact-SQL Óï¾ä»òÅú´¦Àí²»°üº¬²ÎÊý£¬Ôò²»ÐèÒª @params
¡£¸Ã²ÎÊýµÄĬÈÏֵΪ NULL¡£
[@
param1
=
] '
value1
'
²ÎÊý×Ö·û´®Öж¨ÒåµÄµÚÒ»¸ö²ÎÊýµÄÖµ¡£¸ÃÖµ¿ÉÒÔÊdz£Á¿»ò±äÁ¿¡£±ØÐëΪ stmt
Öаüº¬µÄÿ¸ö²ÎÊýÌṩ²ÎÊýÖµ¡£Èç¹û stmt
Öаüº¬µÄ Transact-SQL Óï¾ä»òÅú´¦ÀíûÓвÎÊý£¬Ôò²»ÐèÒªÖµ¡£
n
¸½¼Ó²ÎÊýµÄÖµµÄռλ·û¡£ÕâЩֵֻÄÜÊdz£Á¿»ò±äÁ¿£¬¶ø²»ÄÜÊǸü¸´Ôӵıí´ïʽ£¬ÀýÈ纯Êý»òʹÓÃÔËËã·ûÉú³ÉµÄ±í´ïʽ¡£
·µ»Ø´úÂëÖµ
0£¨³É¹¦£©»ò 1£¨Ê§°Ü£©
½á¹û¼¯
´ÓÉú³É SQL ×Ö·û´®µÄËùÓÐ SQL Óï¾ä·µ»Ø½á¹û¼¯¡£
Àý×Ó£¨¸Ðл×Þ½¨Ìṩ£©
declare @user varchar(1000)
declare @moTable varchar(20)
select @moTable = 'MT_10'
--¶¨Òå±äÁ¿,×¢ÒâÀàÐÍ
declare @sql nvarchar(4000) 
--Ϊ±äÁ¿¸³Ö


Ïà¹ØÎĵµ£º

sql 2005 ´æ´¢¹ý³Ì·ÖÒ³ java ´úÂë

 create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',         
@pagesize int output,--ÿҳÏÔʾ¼Ç¼ÌõÊý
@currentpage int output,--µÚ¼¸Ò³
@orderid nvarchar(50),--Ö÷¼üÅÅÐò
@sort int,--ÅÅÐò·½Ê½£¬1±íʾÉýÐò£¬0±íʾ½µÐòÅÅÁÐ ......

SQL °´Ô²éѯ

ÏîÄ¿ÖÐÐèÒª¸ù¾Ý¿Î¼þÃû³Æ°´ÔÂͳ¼Æ³ö·ÃÎʵÄÇé¿ö£¬µÚÒ»´ÎÎÒ²ÉÓÃÁË×îÍÁµÄÒ»ÖÖ°ì·¨£¬Ê¹ÓÃÑ­»·£¬¸øsql´«µÝÄêÔÂÁ½¸ö²ÎÊý£¬
for(var y=2009;y<=2010;y++){
    for(var m=1;m<=12;m++){
          // todo : SQL ²éѯ
    }
}
ÕâÑù£¬Í³¼Æ2 ......

Sql Server ÖÐÒ»¸ö·Ç³£Ç¿´óµÄÈÕÆÚ¸ñʽ»¯º¯Êý

Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(100), GETDATE(), 4): 16.05.06
Select CONVERT(varch ......

ÐÞ¸ÄSQL SERVERÊý¾Ý¿â±í½á¹¹µÄSQLÃüÁî

¡¡¡¡Ïò±íÖÐÔö¼ÓÒ»¸ö varchar ÁУº
¡¡¡¡ALTER TABLE distributors ADD COLUMN address varchar(30);
¡¡¡¡´Ó±íÖÐɾ³ýÒ»¸ö×ֶΣº
¡¡¡¡ALTER TABLE distributors DROP COLUMN address RESTRICT;
¡¡¡¡ÔÚÒ»¸ö²Ù×÷ÖÐÐÞ¸ÄÁ½¸öÏÖÓÐ×ֶεÄÀàÐÍ£º
¡¡¡¡ALTER TABLE distributors
¡¡¡¡ALTER COLUMN address TYPE varchar(80),
......

Ò»¶ÎsqlÓï¾äµÄ·ÖÎö

--µ±Ç°Ê¹ÓõÄÊý¾Ý¿âÊÇ ÏµÍ³×Ô´øµÄ master
create database temp1
go --´Ë´¦²»¼ÓgoµÄ»°ÏÂÃæuse temp1 »á±¨´í£ºÕÒ²»µ½´æ´¢¹ý³Ì 'temp1'¡£
use temp1
set xact_abort on
begin tran
create table [order]( --orderÊǹؼü×Ö±ØÐëÓÃ[ ]£»
id int
)
create table fOrder(
id int
)
-- ÏÂÃæµÄ²Ù×÷Ö÷ÒªÊÇΪÁËʵÏÖfO ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ