随笔分类 - SqlServer
摘要:从08开始,sql server 提供了一种叫做 变更数据捕获 cdc(Change Data Capture) 的功能,可以通过启用这个功能,来实现查看数据库中的表对象的数据的变化情况。(我感觉就是有点像sql server 自己提供的用户能直接看懂的数据变化功能)。 根据官方的说法。使用cdc
阅读全文
摘要:SELECT top(10) * from (SELECT sys.fn_cdc_map_lsn_to_time([__$start_lsn]) 'addtime',* FROM cdc.dbo_TM_Room_CT)awhere 0=0 列名 数据类型 说明 __$start_lsn binary
阅读全文
摘要:--建立数据库链接服务器 EXEC sp_addlinkedserver @server =N'TestOracle', --要创建的链接服务器别名 @srvproduct=N'Oracle', --产品名称 @provider=N'OraOLEDB.Oracle', --OLE DB 驱动名称 @
阅读全文
摘要:--sqlserver SELECT TOP 100 * FROM dbo.T_TASK --oracle select * from TASK where rownum<100 --mysql SELECT * FROM T_TASK limit 0,100
阅读全文
摘要:SELECT DATEADD(YEAR,-1,'2017-07-13') --2016-07-13
阅读全文
摘要:例子: select count(*) from table where DATEDIFF ([second], '2004-09-18 00:00:18', '2004-09-18 00:00:19') > 0 说明 select DATEDIFF(day, time1 , time2) 对应示例
阅读全文
摘要:首先是ef的多数据库操作实现事务的方法 public int AddDifferenceDB(userinfo1 user1, userinfo user) { int result = 0; using (var test2DB = new test2Entities1()) { using (v
阅读全文
摘要:null和其他值比较都是unknown 在SQL中逻辑表达式的可能值包括TRUE、FALSE、UNKNOWN。他们被称为三值逻辑。三值逻辑是SQL所特有的。大多数的变成语言的逻辑表达式 只有TRUE或FALSE两种值。SQL中的UNKNOWN通常出现在包含NULL值的逻辑表达式中(例如,下面的逻辑值
阅读全文
摘要:1.内部事物 需 using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) 否则会出现“已终止事物” 的错误 TransactionScope 分布式事务的使用案例 以及简单说明
阅读全文
摘要:公司之前一直存在一个规范,就是禁止嵌套事务的使用,一直不太明白为什么,试了下应该是无法控制回滚,今天看大牛的博客发现,问题远远不只如此。 具体总结下来是以下3个问题 1、内层事务回滚,只能回滚全部事务,无法控制单一事务回滚 2、内层事务提交后,回滚外层事务,也会把内层提交了的事务一起回滚 3、因为2
阅读全文
摘要:use master if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop proce
阅读全文
摘要:create table #ttt(id int,name nvarchar(10));merge into #ttt t using (select 1 as id ,'eee' as name ) b on (t.id = b.id) when matched then update set t...
阅读全文
摘要:--方法1DECLARE @Table NVARCHAR(30)DECLARE tmpCur CURSOR FORSELECT name FROM sys.objects WHERE TYPE='U' AND name LIKE N'HSUPA%'OPEN tmpCurFETCH NEXT FROM...
阅读全文
摘要:/****** Script for SelectTopNRows command from SSMS ******/declare @oid int declare @cid int declare @tb table(oid int not null primary key,cid int ...
阅读全文
摘要:有三种用法1.insert values2.insert select3.inser exec
阅读全文
摘要:sql server 查询某个表的所有触发器名称查出所有用到某个表的SQLselect * from sysobjects where xtype='TR' select * from sysobjects where xtype='TR' and parent_obj=object_id('表名'...
阅读全文
摘要:--递归查询 with cte as ( select a.ID,a.Text, a.Name,a.PID from Menu a where id='2' union all select k.id,k.Text, k.name,k.pid from ...
阅读全文
摘要:select tid,tid+ coalesce(tid0,'101') from article where id=1 ---如果tid为null 则 返回101 select LEN('你好 啊') select datalength(N'abcd') ---返回字节数 ,N 占2字节sele...
阅读全文
摘要:---新增列alter table articleadd addtime0 datetime---修改列alter table articlealter column addtime0 varchar(100)--删除列alter table articledrop column addtim...
阅读全文
摘要:当几个用户需要在某个特定的数据库中执行类似的动作时(这里没有相应的Windows用户组),就可以向该数据库中添加一个角色(role)。数据库角色指定了可以访问相同数据库对象的一组数据库用户。数据库角色的成员可以分为如下几类:Windows用户组或用户账户SQL Server登录其他角色SQL Ser...
阅读全文