SELECT TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = '列名'
select * from [表A] where 有重复数据的列名 in (select 列名 from [表A] group by 列名 having count(列名) >1 )
SELECT * FROM sysobjects s
WHERE TYPE='u'
AND id IN(
SELECT id FROM syscolumns s
WHERE s.[name]='字段名')
select s.*
from(
select *,row_number() over (partition by 列名 order by 排序列名 ASC) as group_idx from 表名
)s where s.group_idx = 1
例如:
select SUBSTRING('abcde',1,2) 返回结果 ab
select SUBSTRING('abcde',2,3) 返回结果 bcd
select SUBSTRING('abcde',1,0) 返回结果为空
select * from 表名 where instr(字段名,chr(13))>0
SELECT DB_NAME() AS DbName,
name AS FileName,
size/128.0 AS CurrentSizeMB,
size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS INT)/128.0 AS FreeSpaceMB
FROM sys.database_files;
SELECT * FROM
[Master].[dbo].[SYSPROCESSES] WHERE [DBID]
IN
(
SELECT
[DBID]
FROM
[Master].[dbo].[SYSDATABASES]
WHERE
NAME='databaseName'
)
注:databaseName 是需要查看的数据库,然后查询出来的行数,就是当前的sql server数据库连接数。不过里面还有一些别的状态可以做参考用。
1.SELECT Round(列名,保留小数的位数) FROM 表名;
2.SELECT Convert(decimal(18,保留小数的位数), 列名) FROM 表名;
--整数部分若为0则会被省略。例如0.5521执行语句后为.55,解决方法见下面3语句
3.SELECT convert(varchar,convert(decimal(18,保留小数的位数),列名)) FROM 表名;
...
(未完待续。。。)