Oracle|sql server|access 数据库里的所有表名,字段名
Oracle|sql server|access 数据库教程里的所有表名,字段名
select * from user_tables where table_name = '用户名'
如果是用该用户登录使用以下语句:
SELECT *
FROM USER_TABLES;
如果是用其他用户:
SELECT * FROM ALL_TABLES WHERE OWNER='USER_NAME'
首先,第一句:是查询的该用户下的所有表吗?一般的普通用户,只是授予了connect 和 resource权限,也可以查看部分系统表吗?
怎样查看该用户【以该用户登录】下的自己创建的所有表呢?
其次,第二句,当我以sys身份登录时,怎么不可以使用这一句呢?SELECT *
FROM ALL_TABLES WHERE OWNER='xiaoming'【xiaoming是我自己创建的用户,只是授予了connect 和 resource权限】
SQL SERVER
查看所有表名:
select name from sysobjects where type='U'
查询表的所有字段名:
Select name from syscolumns Where ID=OBJECT_ID('表名')
select * from information_schema.tables
select * from information_schema.views
select * from information_schema.columns
ACCESS
查看所有表名:
select name from MSysObjects where type=1 and flags=0
MSysObjects是系统对象,默认情况是隐藏的。通过工具、选项、视图、显示、系统对象可以使之显示出来。
参考:sql server获取库名,表名
1.获取表的基本字段属性
--获取SqlServer中表结构
SELECT syscolumns.name,systypes.name,syscolumns.isnullable,
syscolumns.length
FROM syscolumns, systypes
WHERE syscolumns.xusertype = systypes.xusertype
AND syscolumns.id = object_id('你的表名')
2.获取字段的描述信息
--获取SqlServer中表结构 主键,及描述
declare @table_name as varchar(max)
set @table_name = '你的表名'
select sys.columns.name, sys.types.name, sys.columns.max_length, sys.columns.is_nullable,
(select count(*) from sys.identity_columns where sys.identity_columns.object_id = sys.columns.object_id and sys.columns.column_id = sys.identity_columns.column_id) as is_identity ,
(select value from sys.extended_properties where sys.extended_properties.major_id = sys.columns.object_id and sys.extended_properties.minor_id = sys.columns.column_id) as description
from sys.columns, sys.tables, sys.types where sys.columns.object_id = sys.tables.object_id and sys.columns.system_type_id=sys.types.system_type_id and sys.tables.name=@table_name order by sys.columns.column_id
3.单独查询表的递增字段
--单独查询表递增字段
select [name] from syscolumns where
id=object_id(N'你的表名') and COLUMNPROPERTY(id,name,'IsIdentity')=1
4.获取表的主外键
--获取表主外键约束
exec sp_helpconstraint '你的表名' ;
5.相当完整的表结构查询
--很全面的表结构
exec sp_helpconstraint '你的表名' ;
SELECT 表名 = CASE a.colorder WHEN 1 THEN c.name ELSE '' END,
序 = a.colorder,
字段名= a.name,
标识 = CASE COLUMNPROPERTY(a.id,a.name,'IsIdentity') WHEN 1 THEN '√' ELSE '' END,
主键 = CASE
WHEN EXISTS ( SELECT * FROM sysobjects WHERE xtype='PK'
AND name IN (SELECT [name] FROM sysindexes WHERE id=a.id
AND indid IN (SELECT indid FROM sysindexkeys WHERE id=a.id
AND colid IN (SELECT colid FROM syscolumns WHERE id=a.id
AND name=a.name)))) THEN '√' ELSE '' END,
类型= b.name,
字节数= a.length,
长度 = COLUMNPROPERTY(a.id,a.name,'Precision'),
小数 = CASE ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0) WHEN 0 THEN '' ELSE CAST(COLUMNPROPERTY(a.id,a.name,'Scale') AS VARCHAR) END,
允许空= CASE a.isnullable WHEN 1 THEN '√' ELSE '' END,
默认值= ISNULL(d.[text],''),
说明 = ISNULL(e.[value],'')
FROM syscolumns a
LEFT JOIN systypes b ON a.xtype=b.xusertype
INNER JOIN sysobjects c ON a.id=c.id AND c.xtype='U' AND c.name<>'dtproperties'
LEFT JOIN syscomments d ON a.cdefault=d.id
LEFT JOIN sys.extended_properties e ON a.id=e.class AND a.colid=e.minor_id
ORDER BY c.name, a.colorder
6.获取所有的库名
--获取服务器中的所遇库名
select * from master..sysdatabases
7.获取服务器上所有库的所有表
--获取服务器上所有库的所有表名
use master
declare @db_name varchar(100)
declare @sql varchar(200)
declare cur_tables cursor
for
select name from sysdatabases /*where name like 'by_%'*/
open cur_tables
fetch next from cur_tables into @db_name
while @@fetch_status = 0
begin
--set @db_name = @db_name + '.dbo.sysobjects'
print @db_name
set @sql = 'select * from ' + @db_name + '.dbo.sysobjects where xtype =''U'''
exec (@sql)
fetch next from cur_tables into @db_name
end
close cur_tables
deallocate cur_tables
go
补充:数据库,Mssql