SQL Server ÓÅ»¯´æ´¢¹ý³ÌµÄÆßÖÖ·½·¨
ÓÅ»¯´æ´¢¹ý³ÌÓкܶàÖÖ·½·¨£¬ÏÂÃæ½éÉÜ×î³£ÓõÄ7ÖÖ¡£
1.ʹÓÃSET NOCOUNT ONÑ¡Ïî
ÎÒÃÇʹÓÃSELECTÓï¾äʱ£¬³ýÁË·µ»Ø¶ÔÓ¦µÄ½á¹û¼¯Í⣬»¹»á·µ»ØÏàÓ¦µÄÓ°ÏìÐÐÊý¡£Ê¹ÓÃSET NOCOUNT ONºó£¬³ýÁËÊý¾Ý¼¯¾Í²»»á·µ»Ø¶îÍâµÄÐÅÏ¢ÁË£¬¼õСÍøÂçÁ÷Á¿¡£
2.ʹÓÃÈ·¶¨µÄSchema
ÔÚʹÓÃ±í£¬´æ´¢¹ý³Ì£¬º¯ÊýµÈµÈʱ£¬×îºÃ¼ÓÉÏÈ·¶¨µÄSchema¡£ÕâÑù¿ÉÒÔʹSQL ServerÖ±½ÓÕÒµ½¶ÔӦĿ±ê£¬±ÜÃâÈ¥¼Æ»®»º´æÖÐËÑË÷¡£¶øÇÒËÑË÷»áµ¼Ö±àÒëËø¶¨£¬×îÖÕÓ°ÏìÐÔÄÜ¡£±ÈÈçselect * from dbo.TestTable±Èselect * from TestTableÒªºÃ¡£from TestTable»áÔÚµ±Ç°SchemaÏÂËÑË÷£¬Èç¹ûûÓУ¬ÔÙÈ¥dboÏÂÃæËÑË÷£¬Ó°ÏìÐÔÄÜ¡£¶øÇÒÈç¹ûÄãµÄ±íÊÇcsdn.TestTableµÄ»°£¬ÄÇôselect * from TestTable»áÖ±½Ó±¨ÕÒ²»µ½±íµÄ´íÎó¡£ËùÒÔдÉϾßÌåµÄSchemaÒ²ÊÇÒ»¸öºÃÏ°¹ß¡£
3.×Ô¶¨Òå´æ´¢¹ý³Ì²»ÒªÒÔsp_¿ªÍ·
ÒòΪÒÔsp_¿ªÍ·µÄ´æ´¢¹ý³ÌĬÈÏΪϵͳ´æ´¢¹ý³Ì£¬ËùÒÔÊ×ÏÈ»áÈ¥master¿âÖÐÕÒ£¬È»ºóÔÚµ±Ç°Êý¾Ý¿âÕÒ¡£½¨ÒéʹÓÃUSP_»òÕßÆäËû±êʶ¿ªÍ·¡£
4.ʹÓÃsp_executesqlÌæ´úexec
ÔÒòÔÚInside Microsoft SQL Server 2005 T-SQL ProgrammingÊéÖеĵÚËÄÕÂDynamic SQLÀïÃæÓоßÌåÃèÊö¡£ÕâÀïÖ»ÊǼòµ¥ËµÃ÷һϣºsp_executesql¿ÉÒÔʹÓòÎÊý»¯£¬´Ó¶ø¿ÉÒÔÖØÓÃÖ´Ðмƻ®¡£exec¾ÍÊÇ´¿Æ´SQLÓï¾ä¡£
5.ÉÙʹÓÃÓαê
¿ÉÒԲο¼Inside Microsoft SQL Server 2005 T-SQL ProgrammingÊéÖеĵÚÈýÕÂCursorsÀïÃæÓоßÌåÃèÊö¡£×ÜÌåÀ´Ëµ£¬SQLÊǸö¼¯ºÏÓïÑÔ£¬¶ÔÓÚ¼¯ºÏÔËËã¾ßÓнϸߵÄÐÔÄÜ£¬¶øCursorsÊǹý³ÌÔËËã¡£±ÈÈç¶ÔÒ»¸ö100ÍòÐеÄÊý¾Ý½øÐвéѯ£¬ÓαêÐèÒª¶Á±í100Íò´Î£¬¶ø²»Ê¹ÓÃÓαêÖ»ÐèÒªÉÙÁ¿¼¸´Î¶ÁÈ¡¡£
6.ÊÂÎñÔ½¶ÌÔ½ºÃ
SQL ServerÖ§³Ö²¢·¢²Ù×÷¡£Èç¹ûÊÂÎñ¹ý¶à¹ý³¤£¬»òÊǸôÀ뼶±ð¹ý¸ß£¬¶¼»áÔì³É²¢·¢²Ù×÷µÄ×èÈû£¬ËÀËø¡£´ËʱÏÖÏóÊDzéѯ¼«Âý£¬Í¬Ê±cupÕ¼ÓÃÂʼ«µÍ¡£
7.ʹÓÃtry-catchÀ´´¦Àí´íÎóÒì³£
SQL Server 2005¼°ÒÔÉÏ°æ±¾Ìṩ¶Ôtry-catchµÄÖ§³Ö£¬Ó﷨Ϊ£º
begin try
----your code
end try
begin catch
--error dispose
end catch
Ò»°ãÇé¿ö¿ÉÒÔ½«try-catchͬÊÂÎñ½áºÏÔÚÒ»ÆðʹÓá£
begin try
begin tran
--select
--update
--delete
--……&he
Ïà¹ØÎĵµ£º
SQL Serverµ¼³ö±íµ½EXCELÎļþµÄ´æ´¢¹ý³Ì
·¢²¼Ê±¼ä£º2008.07.11 09:00 À´Ô´£ºÈüµÏÍø ×÷ÕߣºÐ¡ÇÇ
¡¾ÈüµÏÍø£IT¼¼Êõ±¨µÀ¡¿SQL Serverµ¼³ö±íµ½EXCELÎļþµÄ´æ´¢¹ý³Ì:
*--Êý¾Ýµ¼³öEXCEL
µ¼³ö±íÖеÄÊý¾Ýµ½Excel,°üº¬×Ö¶ÎÃû,ÎļþΪÕæÕýµÄExcelÎļþ
,Èç¹ ......
½ñÌì°²×°SQL SERVER 2000 ¸öÈ˰棬°²×°×îºóµ¯³ö´íÎó¶Ô»°¿ò£º
“°²×°³ÌÐòÅäÖ÷þÎñÆ÷ʧ°Ü¡£²Î¿¼·þÎñÆ÷´íÎóÈÕÖ¾ºÍC:\windows\sqlstp.log”£¬´Ó¶øÎÞ·¨°²×°¡£
µ½¾ßÌåµÄĿ¼²é¿´ÏÔʾ"Ò»°ãÐÔÍøÂç´íÎó"£¬ÔÚÍøÉÏËÑË÷ÎÊÌâÔÒò¼°½â¾ö·½°¸ÈçÏ£º
´ËÎÊÌâÊôÓÚsql serverµÄbug, GetComputerName ÓÃÓÚ»ñÈ¡±¾µØ¼ÆËã»úÃû¡£ ......
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), GE ......
sql2005ÖÐÒ»¸öxml¾ÛºÏµÄÀý×Ó ÊÕ²Ø
¸ÃÎÊÌâÀ´×ÔÂÛ̳ÌáÎÊ£¬ÑÝʾSQL´úÂëÈçÏÂ
--½¨Á¢²âÊÔ»·¾³
set nocount on
create table test(ID varchar(20),NAME varchar(20))
insert into test select '1','aaa'
insert into test select '1','bbb'
insert into test select '1','ccc'
insert into test select '2','ddd'
inser ......
--
¾ÛºÏº¯Êý
use
pubs
go
select
avg
(
distinct
price)
--
Ëãƽ¾ùÊý
from
titles
where
type
=
'
business
'
go
use
pubs
go
select
max
(ytd_sales)
--
×î´óÊý
from
titles
go
use
pubs
go
select
min
(ytd_sales)
--
×îСÊý
fr ......