MS SQL(SQL Server)技巧
判断某个表中是否存在某列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 = dbConn.prepareStatement(strPreSQL);
用SQL Server驱动一次select很多数据最好在connection string中加上SelectMethod=Cursor,以利用服务器端游标加快速度,其实不只sqlserver,oracle的jdbc,只要使用PreparedStatement,驱动默认就使用游标,sqlserver则不然,必须使用SelectMethod=Cursor才打开游标。
页:
[1]