SqlServerÊý¾Ý¿âµÄÓï¾ä¼°Ò»Ð©²Ù×÷ÕûÀí
ÁÙ½üÄêÖÕ£¬ÔÚ¹¤×÷Ö®Óà¶Ô¹¤×÷ºÍѧϰÖÐÓöµ½µÄÎÊÌâÒÔ¼°³£ÓõÄһЩ֪ʶµã×öÁËЩÕûÀí£¬ÒÔ±¸ºóÓᣱ¾ÎÄÉæ¼°µÄÄÚÈÝΪÊý¾Ý¿â,ËãÊǶԿª·¢×ܽá(1)---Êý¾Ý¿âÒ»ÎĵIJ¹³ä¡£
1 ¶ÔÓÚÖ÷¼üÉèÖÃÁËIdentityµÄ±í£¬ÔÚɾ³ý±íÖÐÊý¾ÝºóÔÙÍù±íÖвåÈëÊý¾Ý£¬IdentityÁв»ÊÇ´Ó1ÆðʼÁË£¬Èç¹ûÏëɾ³ýÊý¾ÝºóIndentityÁÐÈÔ´Ó1Æðʼ£¬¿ÉÒÔÓÃÏÂÃæ´úÂëÀ´É¾³ýÊý¾Ý¡£
truncate table tablename
DBCC CHECKIDENT(tablename,RESEED,1)
2 ÅжÏÖ¸¶¨±íÔÚÊý¾Ý¿âÖÐÊÇ·ñ´æÔÚ
if exists(select name from sysobjects where name='tablename' and type='u')
3 ÅжÏÖ¸¶¨ÁÐÔÚÖ¸¶¨±íÖÐÊÇ·ñ´æÔÚ
if exists(select * from sys.columns,sys.tables
where sys.columns.object_id = sys.tables.object_id
and sys.tables.name='tablename' and sys.columns.[name]='columnname')
4 ÔÚ±àд´úÂëÉú³ÉÆ÷Ö®ÀàµÄ³ÌÐòµÄʱºò£¬Í¨³£ÐèҪȡ³öÊý¾Ý¿âÖÐËùÓеıíÃûÒÔ¼°±íÖÐ×ֶεÄһЩ»ù±¾ÐÅÏ¢£¬Èç×ֶγ¤¶È¡¢×Ö¶ÎÀàÐÍ¡¢ÃèÊöµÈ¡£ÊµÏÖÉÏÃæÒªÇóµÄsqlÓï¾äÈçÏ£º
--È¡Êý¾Ý¿âÖбíµÄ¼¯ºÏ
select * from sysobjects where xtype='u' order by name
--È¡±íÖÐ×ֶεÄһЩ»ù±¾ÐÅÏ¢
select
sys.columns.name, --×Ö¶ÎÃû
sys.types.name as typename, --×Ö¶ÎÀàÐÍ
sys.columns.max_length, --×ֶ㤶È
sys.columns.is_nullable, --ÊÇ·ñ¿É¿Õ
(select
count(*)
from
sys.identity_columns
where
sys.identity_columns.object_id = sys.columns.object_id
and
sys.columns.column_id = sys.identity_columns.column_id
) as is_identity ,--ÊÇ·ñ×ÔÔö
(select
value
from
sys.extended_properties
where
sys.extended_properties.major_id = sys.columns.object_id
and
sys.extended_properties.minor_id = sys.columns.column_id
) as description --×¢ÊÍ
from
sys.columns, sys.tables, sys.types
where
sys.columns.object_id = sys.tables.object_id
and
sys.columns.system_type_id=sys.types.system_type_id
and
sys.tables.name='tablename'
order by sys.columns.column_id
5 ÔÚ´æ´¢¹ý³ÌÖÐʹÓÃÊÂÎñ
create procedure procname
as
begin tran
--Ö´ÐÐsqlÓï¾ä
if @@ERROR!=0
begin
Ïà¹ØÎĵµ£º
SqlserverµÃµ½ºº×ÖÆ´ÒôÊ××Öĸ´æ´¢¹ý³Ì:
create function [dbo].[fun_getPY]
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--Èç¹û·Çºº×Ö×Ö·û£¬·µ»ØÔ×Ö·û
& ......
¿ÉÒÔÓÃÀ©Õ¹´æ´¢¹ý³Ìxp_dirtree»ñÈ¡ÎļþÁÐ±í£¬ÓÃopenrowsetµ¹ÈëÊý¾Ýµ½¶þ½øÖÆ×ֶΡ£
openrowsetµÄÓ÷¨¿ÉÒԲο¼msdn
http://technet.microsoft.com/zh-cn/library/ms190312.aspx
Èç¹ûÎļþºÜ¶à£¬½¨Ò黹ÊÇÓóÌÐòµ¹ÈëÁË
if (object_id ('t_bulkResult' ) is not null )
drop table t_bulkResult ......
SQLServerÖÐÓÐÁ½¸öÀ©Õ¹´æ´¢¹ý³ÌʵÏÖScanfºÍPrintf¹¦ÄÜ£¬Ç¡µ±µÄʹÓÃËüÃÇ¿ÉÒÔÔÚÌáÈ¡ºÍÆ´½Ó×Ö·û´®Ê±´ó·ù¶È¼ò»¯SQL´úÂë¡£
1¡¢xp_sscanf£¬ÓÃËü¿ÉÒÔ·Ö½â¸ñʽÏà¶Ô¹Ì¶¨µÄ×Ö·û´®£¬Õâ¶ÔÓÚÑá¾ëʹÓÃÒ»¶ÑsubstringºÍcharindexµÄÅóÓÑÀ´Ëµ²»´í¡£±ÈÈçǰ¼¸ÌìµÄÒ»¸öÌû×ÓÖÐÌá³öµÄÈçºÎ·Ö½âipµØÖ·£¬Ïà¶Ô¼òÁ·ÇÒͨÓõĴúÂëÓ¦¸ÃÊÇÏÂÃæÕâÑù
------- ......
HOLDLOCK ½«¹²ÏíËø±£Áôµ½ÊÂÎñÍê³É£¬¶ø²»ÊÇÔÚÏàÓ¦µÄ±í¡¢ÐлòÊý¾ÝÒ³²»ÔÙÐèҪʱ¾ÍÁ¢¼´ÊÍ·ÅËø¡£HOLDLOCK µÈͬÓÚ SERIALIZABLE¡£
NOLOCK ²»Òª·¢³ö¹²ÏíËø£¬²¢ÇÒ²»ÒªÌṩÅÅËüËø¡£µ±´ËÑ¡ÏîÉúЧʱ£¬¿ÉÄÜ»á¶ÁȡδÌá½»µÄÊÂÎñ»òÒ»×éÔÚ¶ÁÈ¡ÖÐ¼ä»Ø¹öµÄÒ³Ãæ¡£ÓпÉÄÜ·¢ÉúÔà¶Á¡£½öÓ¦ÓÃÓÚ SELECT Óï¾ä¡£
PAGLOCK ÔÚͨ³£Ê¹Óõ¥¸ö±íËøµ ......
±¾ÎÄÀ´×ÔCSDN²©¿Í£ºhttp://blog.csdn.net/jinjazz/archive/2008/07/14/2650506.aspx
½«oledb¶ÁÈ¡µÄexcelÊý¾Ý¿ìËÙ²åÈëµÄsqlserverÖУ¬ºÜ¶àÈËͨ¹ýÑ»·À´Æ´½Ósql£¬ÕâÑù×ö²»µ«ÈÝÒ׳ö´í¶øÇÒЧÂʵÍÏ£¬×îºÃµÄ°ì·¨ÊÇʹÓÃbcp£¬Ò²¾ÍÊÇSystem.Data.SqlClient.SqlBulkCopy ÀàÀ´ÊµÏÖ¡£²»µ«Ëٶȿ죬¶øÇÒ´úÂë¼òµ¥£¬ÏÂÃæ²âÊÔ´úÂëµ¼ÈëÒ»¸ö6 ......