现在的位置: 首页 > 数据库 > 正文

MS SQL(SQL Server)技巧

2018年08月12日 数据库 ⁄ 共 659字 ⁄ 字号 评论关闭

判断某个表中是否存在某列
if exists (select * from syscolumns where id=object_id('table_name') and name='column_name')

判断数据库中是否存在某个表
select * from dbo.sysobjects where id = object_id(N'tablename') and OBJECTPROPERTY(id,

N'IsUserTable') = 1

动态添加Where条件
select * from test where 1=1 ,此后可以动态添加and条件

 

 

SelectMethod=cursor 作用:

在url = "jdbc:microsoft:sqlserver://localhost;DatabaseName=epet"上增加一个SelectMethod=cursor.它的作用是在一个事务中初始化多个预处理句柄.比如:

dbConn.setAutoCommit(false)
for (int i = 0; i < 5; i++) {
pstmt[i] = dbConn.prepareStatement(strPreSQL[i]);

用SQL Server驱动一次select很多数据最好在connection string中加上SelectMethod=Cursor,以利用服务器端游标加快速度,其实不只sqlserver,oracle的jdbc,只要使用PreparedStatement,驱动默认就使用游标,sqlserver则不然,必须使用SelectMethod=Cursor才打开游标。

抱歉!评论已关闭.