SQL 常用系统表

—系统工具
–查询当前数据库中所有表名 xtype=‘U’:表示所有用户表,xtype=‘S’:表示所有系统表。
SELECT * FROM sysobjects WHERE xtype = ‘U’;
SELECT * FROM sysobjects WHERE xtype = ‘S’;

–查询指定表中的所有字段名 id 等于 sysobjects的ID
SELECT * FROM syscolumns WHERE Id = ‘107141’;

–查询数据库中所有的表名及行数
SELECT a.name, b.rows
FROM sysobjects AS a
INNER JOIN sysindexes AS b ON a.id = b.id
WHERE (a.type = ‘u’) AND (b.indid IN (0, 1))
ORDER BY a.name,b.rows DESC

–查询所有的标明及空间占用量\行数
select
object_name(id) tablename,
8reserved/1024 reserved,
rtrim(8
dpages)+‘kb’ used,
8*(reserved-dpages)/1024 unused,
8dpages/1024-rows/1024minlen/1024 free,
rows
from sysindexes
where indid=1
ORDER BY used DESC
–order by used,tablename,reserved desc

你可能感兴趣的:(mysql)