随笔分类 - SqlServer
摘要:--查询死锁 SELECT request_session_id sessionid, resource_type type, resource_database_id dbid, OBJECT_NAME(resource_associated_entity_id, resource_databas
阅读全文
摘要:Create FUNCTION [dbo].[dnt_split] ( @splitstring varchar(max), @separator CHAR(1) = ',' ) RETURNS @splitstringstable TABLE ( [Id] int identity(1,1), [
阅读全文
摘要:一、自定义函数: 1. 可以返回表变量 2. 限制颇多,包括 不能使用output参数; 不能用临时表; 函数内部的操作不能影响到外部环境; 不能通过select返回结果集; 不能update,delete,数据库表; 3. 必须return 一个标量值或表变量 自定义函数一般用在复用度高,功能简单
阅读全文
摘要:1 -- 创建语句 2 create table goodsTest(--商品表 3 id int primary key identity(1,1), 4 goosType varchar(100),--商品归类 5 goodsName varchar(100),--商品名称 6 serialNo
阅读全文
摘要:--万能sqlselect convert(varchar(7),dateadd(mm,-number,getdate()),23) as d from master..spt_values where type='p' and number >=0 and number<=5 and conver
阅读全文
摘要:判断临时表是否存在,存在则删除 if OBJECT_ID('tempdb..#tempTable') IS NOT NULL begin DROP TABLE #temp_Table end 创建临时表(' # '局部的临时表仅在会话里边, ' ## '全局的的临时表) create table #
阅读全文
摘要:对Table 表做操作 Table Table(表名),id(Table的自增字段),临时表的定义 用ID递增 去循环 declare @id int =0 while( (select top 1 id from Table where id>@id order by id)>0 ) begin
阅读全文
摘要:declare @str varchar(max) --传递数字 :cloumn int --同义-执行-> select * from table0 where cloumn0=1; set @str='select * from table0 where cloumn0='+1; exec(@s
阅读全文
摘要:用途:跟identity是一个意思区别是identity只能用于一个table,序列可以应用于多个表 格式 CREATE SEQUENCE [schema_name . ] sequence_name [ AS [ built_in_integer_type | user-defined_integ
阅读全文
摘要:插入语句: --通常写法 insert into (列1,列2...) values(值1,值2...) --错误示范 insert into TB2 Select * From TB1 --错误信息 --仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表中的标识列指定显式
阅读全文
摘要:作用 :对数据的多条数据进行逐条更改或者显示。 语句分析: next:返回结果集当前行的下一行,首次提取返回第一行。 frior:返回结果集的上一行,首次提取无数据返回。 first:返回结果集第一行。 last:返回结果集最后一行。 absolute:移动到结果集的第n行。如果n为正数,从结果集的
阅读全文
摘要:触发器: 它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由事件来触发,比如当对一个表进行操作( insert,delete, update)时就会激活它执行。触发器经常用于加强数据的完整性约束和业务规则等。 语法 --创建触发器(DML)create trigger
阅读全文