行列互转 ) select * from test2 --列转行 select id,name,quarter,profile from test2 unpivot ( profile for quarter in ([Q1],[Q2],[Q3],[Q4]) ) as unpvt sql替换字符串 substring replace SQL查询一个表内相同纪录 having 如果一个ID可以区分的话,可以这么写 ) 如果几个ID才能区分的话,可以这么写 其他回答:数据表是zy_bho,想找…
清理数据库日志 USE [master] ALTER DATABASE [表名] SET RECOVERY SIMPLE WITH NO_WAIT ALTER DATABASE [表名] SET RECOVERY SIMPLE GO USE [表名] DECLARE @logname VARCHAR(150) SELECT @logname = NAME FROM sys.database_files WHERE NAME LIKE'%log' DBCC SHRINKFILE(@logname,…
删除数据库所有的表: declare @sql varchar() begin SELECT @sql='drop table ' + name FROM sysobjects WHERE (type = 'U') ORDER BY 'drop table ' + name exec(@sql) end 查询表的字段信息: SELECT (case when a.colorder=1 then d.name else null end) 表名, a.colorder 字段序号,a.name 字段…
--查看指定表的外键约束 select * from sysobjects where parent_obj in( select id from sysobjects where name='表名') and xtype='PK' --查看所有表 select * from sysobjects where xtype='PK' --删除列中含数字的 delete news where patindex('%[0-9]%',title)>0 --删除删去 字段 title值重复的行,且只保留…