就业数据资源平台
当前位置:首页 > PC技术
2012年计算机三级考试PC技术基础知识(44)

1、1=1,1=2的使用,在SQL语句组合时用的较多

  “where 1=1” 是表示选择全部 “where 1=2”全部不选,


  如:


  if @strWhere !=''


  begin


  set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + @strWhere


  end


  else


  begin


  set @strSQL = 'select count(*) as Total from [' + @tblName + ']'


  end


  我们可以直接写成


  set @strSQL = 'select count(*) as Total from [' + @tblName + '] where 1=1 安定 '+ @strWhere


        2、收缩数据库


  --重建索引


  DBCC REINDEX


  DBCC INDEXDEFRAG


  --收缩数据和日志


  DBCC SHRINKDB


  DBCC SHRINKFILE

就业数据资源平台