sql获取表名称
‘壹’ 怎样通过sql读取Excel表名
先用函数获取sheet的名字,然后传入select 列表中返回就可以了。
MySheet = Application.Caller.Worksheet.Name
select MySheet ,xxx from 表 where xxx=yyyy
‘贰’ 如何查询SQL的表名
oracle的
select*fromdba_tab_cols
‘叁’ SQL 查表名
你是说用户表。
查询所有表名:
SELECT NAME FROM SYSOBJECTS WHERE TYPE='U'
查询所有内容中包含某字串的表:
EXEC Full_Search '要查的字串'
赠送数据库表内容全文查找存储过程:
CREATE proc Full_Search(@string varchar(50))
as
begin
declare @tbname varchar(50)
declare tbroy cursor for select name from sysobjects
where xtype= 'u ' --第一个游标遍历所有的表
open tbroy
fetch next from tbroy into @tbname
while @@fetch_status=0
begin
declare @colname varchar(50)
declare colroy cursor for select name from syscolumns
where id=object_id(@tbname) and xtype in (
select xtype from systypes
where name in ( 'varchar ', 'nvarchar ', 'char ', 'nchar ') --数据类型为字符型的字段
) --第二个游标是第一个游标的嵌套游标,遍历某个表的所有字段
open colroy
fetch next from colroy into @colname
while @@fetch_status=0
begin
declare @sql nvarchar(1000),@j int
select @sql= 'select @i=count(1) from ' +@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%'''
exec sp_executesql @sql,N'@i int output',@i=@j output --输出满足条件表的记录数
if @j> 0
exec( 'select distinct 表名='''+@tbname+''','+@colname+ ' from ' +@tbname + ' where '+ @colname+ ' like '+ '''%'+@string+ '%''')
fetch next from colroy into @colname
end
close colroy
deallocate colroy
fetch next from tbroy into @tbname
end
close tbroy
deallocate tbroy
end
GO
‘肆’ sql server 怎么获取表字段名称
1、方法一
SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='表名'
2、方法二
select a.name tablename, b.name colName, c.name colType ,c.length colLength
from sysobjects a inner join syscolumns b
on a.id=b.id and a.xtype='U'
inner join systypes c
on b.xtype=c.xusertype
where a.name='表名'
‘伍’ sql怎么得到所有表名
获取所有表名:
SELECT Name FROM DatabaseName..SysObjects Where XType='U' ORDER BY Name
SELECT Name FROM Master..SysObjects Where XType='U' ORDER BY Name
类型和名称
select c.name,s.name from syscolumns c left join systypes s on c.xtype = s.xtype where c.id = OBJECT_ID('cnMarkMap_Users')
XType='U':表示所有用户表;
XType='S':表示所有系统表;
‘陆’ 如何解析sql语句并提取出表名
先做词法分析,识别每个单词, 然后做语义分析找到表名。
关键字from、into后, where前就是表名。
select * from table_name where .....;
insert a, b, c into table_name;
delete * from table where ...;
update f1 = a table where ...;