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
相关文档:
--语 句 功 能
--数据操作
SELECT --从数据库表中检索数据行和列
INSERT --向数据库表添加新数据行
DELETE --从数据库表中删除数据行
UPDATE --更新数据库表中的数据
--数据定义
CREATE TABLE --创建一个数据库表
DROP TABLE --从数据库中删除表
ALTER TABLE --修改数据库表结构
CREATE VIEW --创建一个视图
DRO ......
今天下了个WIN7的英文包把系统换成英文的。感觉还行,可是当创建数据库表时发现出错了,查了下才知道是SQL的排序出问题了
下面是CTRL+c V搞过来的,只是方便大家有这样的问题可以得到解决
使用SQL2005进行创建数据库的时候,如果遇到创建失败的情况,如下:
Create 对于 数据库“xxxx”失败。 (Microsoft.SqlS ......
-- 查看当前db的登陆
select * from sys.sql_logins
-- 审核登陆数据库的用户
sql server managerment studio中,右键点开服务器的属性,在安全性页签中, 选中审核“成功和失败的登陆”,所有登陆都会在..MSSQL\Log\ERRORLOG中记录一条记录。
如果勾选“启用C2审核跟踪”,将会在..MSSQL\Log\目录 ......
1.删除表
select 'drop table ' || table_name || ' purge;'
from user_tables
where length(table_name) <= 4;
删除带约束的表
Drop table 表名 cascade constraints;
2.查询view&同义词
--说明:可以根据视图的text_length ......
1.求1..10偶数之和
select sum(level) from dual
where mod(level,2)=0
connect by level
2.将update改换成用rowid来实现。
(1)新的写法:
merge into SNAPSHOT120_2010_572 t1
using (select a.rowid rid, b.vip_level, b.manager_name
from xyf_vip_info_new b, snapsho ......