随笔分类 -  Sql server

摘要:昨天给客户导数据,内容表38万条记录,表字段不到100个。用程序分批导。由于标识列 id 里的值有用,所以在导入时把id改为了不自增。导完后,再加为自增列时,提示超时。用语句 alter table rcms_contents alter column [id] bigint identity(1,1) 修改,在sql08下提示语法错误。于是找高手,上网查,解决了。方法如下: 1、先把数据加到临时表里,一会儿会用到 select * into #content from content 2、先加一列id_1设为自增列 alter table rcms_Contents add id_1... 阅读全文
posted @ 2013-08-14 12:04 我在这 阅读(4035) 评论(2) 推荐(0)
摘要:转载....AndyJanCREATEfunctionGet_StrArrayLength(@strvarchar(1024),--要分割的字符串@splitvarchar(10)--分隔符号)returnsintasbegindeclare@locationintdeclare@startintdeclare@lengthintset@str=ltrim(rtrim(@str))set@location=charindex(@split,@str)set@length=1while@location<>0beginset@start=@location+1set@location 阅读全文
posted @ 2013-05-21 11:46 我在这 阅读(336) 评论(0) 推荐(0)
摘要:今天写sql时,用到了count,大家都知道count是统计数量的,因为我不管在写什么统计时,一般都会用直接这么用 select count (*) from 表,不知道其它人在用count时,是不是也是count (*) ,由于我们的数据库数据量是在40W数据之内,且该表字段数量在70个左右,用count(*)时,用时有时会在0-1秒之间,有时会在0秒(有可能是电脑速度问题),就在我查的同时,脑中忽然出现,为什么不直接count(id)呢?id列肯定是不为空的,于是就反复查询count(id),操作其它语句的再进行测试count(id)和count(*),发现用时都是在0秒,但是心里感觉.. 阅读全文
posted @ 2012-12-17 18:25 我在这 阅读(727) 评论(0) 推荐(0)
摘要:declare @tname varchar(8000) set @tname=''select @tname=@tname + Name + ',' from sysobjects where xtype='U'select @tname='drop table ' + left(@tname,len(@tname)-1) exec(@tname) --删除所有存储过程的sql语句 用到游标 declare @procName varchar(500) declare cur cursorfor select [name] fr 阅读全文
posted @ 2012-10-25 18:21 我在这 阅读(401) 评论(0) 推荐(0)