随笔分类 - sql
摘要:Truncate是一个能够快速清空资料表内所有资料的SQL语法。并且能针对具有自动递增值的字段,做计数重置归零重新计算的作用。
阅读全文
摘要:{[^N]}{'[\u4e00-\u9fa5]|[\u4e00-\U9fa5]|[0-9]|[A-Z]}\1N\2
阅读全文
摘要:select cast(round(12.5,2) as numeric(5,2))解释:round()函数,是四舍五入用,第一个参数是我们要被操作的数据,第二个参数是设置我们四舍五入之后小数点后显示几位。numeric函数的2个参数,第一个表示数据长度,第二个参数表示小数点后位数。cast as numeric(5,2)函数,是为了四舍五入之后的数字能确保显示小数点。
阅读全文
摘要:视图中不能声明变量,不能调用存储过程,如果写比较复杂的查询,需要应用存储过程视图也可以和函数结合存储过程通过select或其他语句返回结果集除此之外,存储过程返回结果只有两种方式 1 return,2 output参数(主要)http://blog.csdn.net/liangweiwei130/article/details/6691207IF EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[GL_AllItemNamep]','p') ) --视图v ,存储过程p,表uDROP p
阅读全文
摘要:不能,sqlserver 视图一般不能有变量,也不能带存储过程
阅读全文
摘要:查询数据表
阅读全文
摘要:对于.mdf文件和.ldf数据库文件,首先打开SQL Server Management Studio Express,登陆上后,右键点击数据库,附加->选择目标文件就可以了。
阅读全文
摘要:当 应用select * into a from b order by b1,b2语句时,试图使a表中的物理顺序改变,是 不能够实现的select * into 同时复制了b表的物理结构,所以a表中的顺序和b表中的顺序是一致的。如果想改变a表中的查询排序需要select * from b a order by b1,b2.
阅读全文
摘要:查找 sqlserver 中字符串的ascii码SET TEXTSIZE 0-- Create variables for the character string and for the current -- position in the string.DECLARE @position int, @string char(8)-- Initialize the current position and the string variables.SET @position = 1SET @string = '—销售定转子冲片及转子齿压板等(北京三一)'WHILE @pos
阅读全文
摘要:select * from sysobjects where xtype='TR' and parent_obj=object_id('表名')再用sp_helptext '触发器名' 查内容 比如:exec sp_helptext 'Trig_Group_Delete'
阅读全文
摘要:DBCC CHECKDB ('ufdata_001_2012')--DBCC CHECKDB ('ufdata_202_2012', REPAIR_REBUILD)Use mastergosp_dboption 'ufdata_001_2012', single, true--更改成单用户 alter database test set single_user with rollback immediate --with rollback immediate执行这个命令之后,SQL Server立即断开所有的连接并回退它们的事务。所有正在执行事务
阅读全文
摘要:select * from tempdb..TempTable2012040609301854 declare @autoid as integer select @autoid =autoid from tempdb..TempTable2012040609301854 order by iyperiod,corder print @autoid select * from tempdb..TempTable2012040609301854 where autoid = @autoid 或者: select top 1 * from tempdb..TempTable20120406093.
阅读全文
摘要:1 分页排序功能按照物理表存储的顺序显示第10-30条记录select top 20 * from ( select row_number() over (oder by i_id) as rowid fromtableName ) a where rowid>10 and rowid<=302 分组汇总功能select columnA,row_number() over (partiton by columnA order by i_id ) as rowidFROM tableName按照columna进行分组,每一个columnA值rowid从1开始排序。select col
阅读全文
摘要:抛出用户定义的错误信息语法RAISERROR ( { msg_id | msg_str } { , severity , state } [ , argument [ ,...n ] ] ) [ WITH option [ ,...n ] ]1 msg_id用户定义的错误信息号,错误号必须介于 13000 到 2147483647 之间,而且不能是 50000。例如:RAISERROR (13002, -- Message text. 16, -- Severity. 1 -- State. );select @@ERROR显示结果:消息 13002,级别 16,状态 1,第 2 行审核 (为
阅读全文
摘要:对同一数据库下的多个数据表的同一字段进行处理举例例如多个数据表中都含有csign字段,需要替换空格为空,‘’1 查询含有该字段的数据表名称 select sc.name,so.name from syscolumns sc left join sysobjects so on sc.id=so.id where sc.name='csign' and so.type='u'或 select so.name from sysobjects so where so.id in (select id from syscolumns where name='cs
阅读全文

浙公网安备 33010602011771号