SQL查询数据库中每张表的记录数
本文来自:http://hi.baidu.com/darkroot/blog/item/7b74be2cf06d76e78b139903.html
declare @tbName nvarchar(500)
declare @ct int
declare @csql nvarchar(500)
declare #tb cursor for SELECT OBJECT_NAME (id) As TableName from sysobjects WHERE xtype = 'U' AND OBJECTPROPERTY (id, 'IsMSShipped') = 0
open #tb
fetch next from #tb into @tbName
while @@fetch_status=0
begin
set @csql = N'Select @ct= Count(*) from ' + @tbName
Exec dbo.sp_executesql @csql,N'@ct int output',@ct output
Print @tbName + '---' + Cast(@ct As nvarchar(500))
fetch next from #tb into @tbName
end
close #tb
deallocate #tb
相关文档:
【汇总】SQL CODE --- 经典·精彩
数据操作类 SQLHelper.cs
无限级分类 存储过程
百万级分页存储
SQL经典短小代码收集
学生表 课程表 成绩表 教师表
50个常用sql语句
SQL SERVER
与ACCESS、EXCEL的数据转换
游标
根据不同的条件查询不同的表
INNER JOIN 语法
master.dbo.sp ......
-- 查看当前db的登陆
select * from sys.sql_logins
-- 审核登陆数据库的用户
sql server managerment studio中,右键点开服务器的属性,在安全性页签中, 选中审核“成功和失败的登陆”,所有登陆都会在..MSSQL\Log\ERRORLOG中记录一条记录。
如果勾选“启用C2审核跟踪”,将会在..MSSQL\Log\目录 ......
SQL Select Into语句
The SELECT INTO Statement
SELECT INTO 语句
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
SELECT INTO语句常用来给数据表建立备份或是历史档案。
Syntax
语法
SELECT column_name(s) INTO newtable [IN externaldatabase] ......
1。企业管理器
打开你建有外键的表--右击表--设计表--在上方点开’管理约束‘--将级连删除和级连更新的沟打上就可以了
2。查询分析器
alter table sc
add
constraint forei ......