随笔分类 -  SQL

摘要:1.使用函数(sql2000以上) 调用如下: 如果你希望做成通用函数,类似如下:(其实是不可行的) 由于Function里不支持 exec / sp_executesql ,所以这个是做不到的 只能修改成存储过程方式 调用如下: 阅读全文
posted @ 2018-07-31 10:56 zslm___ 阅读(4113) 评论(0) 推荐(0) 编辑
摘要:select top 10 Id,Amount=FLOOR(RAND(ABS(CHECKSUM(NEWID()))) * 100) from Customer 阅读全文
posted @ 2017-09-13 15:53 zslm___ 阅读(222) 评论(0) 推荐(0) 编辑
摘要:1.有用的链接 postgresql 常用小函数 Postgresql数据库的一些字符串操作函数 PostgreSQL function里面调用function PostgreSQL学习手册(函数和操作符<二>) PostgreSQL的存储过程简单入门 2.建立块环境(执行环境) 如 3. 建立存储 阅读全文
posted @ 2017-04-01 16:31 zslm___ 阅读(2164) 评论(0) 推荐(0) 编辑
摘要:MS SqlServer : select top N * from Table1 order by NewId() mySql: SELECT * FROM tableName ORDER BY rand() 阅读全文
posted @ 2017-03-01 09:57 zslm___ 阅读(3968) 评论(0) 推荐(0) 编辑
摘要:identity表导入失败,所以就用了这种笨办法来同步数据 阅读全文
posted @ 2016-11-03 16:42 zslm___ 阅读(160) 评论(0) 推荐(0) 编辑
摘要:declare @t table (logId int,customerId int,amount int) insert into log( customerId,amount) output inserted.Id,inserted.CustomerId,inserted.Amount into 阅读全文
posted @ 2016-10-27 10:24 zslm___ 阅读(2580) 评论(0) 推荐(0) 编辑
摘要:declare @spid int ; declare @ddlstring nvarchar(max); declare @dbname varchar(200); set @dbname='dbName'; declare tmpcur cursor for select distinct spid as spid from sys.sysprocesses where dbid=db_i... 阅读全文
posted @ 2016-09-08 14:48 zslm___ 阅读(199) 评论(0) 推荐(0) 编辑
摘要:sp_executesql 书写规则 exec sp_executesql @sql,N'参数1 类型1,参数2 类型2,参数3 类型3 OUTPUT',参数1,参数2,参数3 OUTPUT; 注意参数顺序必须对应好,习惯上把OUTPUT 参数放在最后 sp_executesql 比 之前的exec 阅读全文
posted @ 2016-06-16 17:48 zslm___ 阅读(150) 评论(0) 推荐(0) 编辑
摘要:1.创建唯一索引 create unique index activityConfigDetail_ConfigIdPageLocationon activityConfigDetail(ConfigId,PageLocation) 2.创建普通索引 create index activityCon 阅读全文
posted @ 2016-06-16 17:30 zslm___ 阅读(153) 评论(0) 推荐(0) 编辑
摘要:set statistics time on 阅读全文
posted @ 2016-06-16 11:04 zslm___ 阅读(140) 评论(0) 推荐(0) 编辑
摘要:UPDLOCK.UPDLOCK 的优点是允许您读取数据(不阻塞其它事务)并在以后更新数据,同时确保自从上次读取数据后数据没有被更改。 当我们用UPDLOCK来读取记录时可以对取到的记录加上更新锁,从而加上锁的记录在其它的线程中是不能更改的只能等本线程的事务结束后才能更改, 更改库存begin tra 阅读全文
posted @ 2016-04-08 22:39 zslm___ 阅读(237) 评论(0) 推荐(0) 编辑
摘要:select *,datediff(ss,(select max( CreateTime) from Table1 b where b.id<a.id),a.CreateTime)from Table1 a Table1表有自增长字段Id Table表的CreateTime也是随着Id而增大的 阅读全文
posted @ 2016-02-18 17:07 zslm___ 阅读(196) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Reflection;using System.Reflection.Emit;namespace SaftS... 阅读全文
posted @ 2015-12-22 11:09 zslm___ 阅读(279) 评论(0) 推荐(0) 编辑
摘要:[转]http://www.cnblogs.com/myhappylife/p/5006774.html1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引。2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用... 阅读全文
posted @ 2015-11-30 17:11 zslm___ 阅读(302) 评论(0) 推荐(0) 编辑
摘要:public int BulkCopyTaskData( string dbTableName, DataTable dt) { int c = 0; if (dt != null && dt.Rows.Count > 0) ... 阅读全文
posted @ 2015-11-27 14:17 zslm___ 阅读(300) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示