查询数据库,发现一些客户自定义的表,开头的字母是小写。我想列出所有的此类表名:
select * from sysobjects where xtype = 'U' and left(name, 1) <> upper(left(name,1))
惊奇地发现,竟然查不到记录。
检查数据库的collation是SQL_Latin1_General_CP1_CI_AS,原来是大小写不敏感。
重写SQL如下,终于获得结果
select * from sysobjects where xtype = 'U' and (convert(binary,left(name, 1)) <> convert(binary,upper(left(name,1))))