sql如何查某个表某个字段的数据类型?
select a.name as [column],b.name as type
from syscolumns a,systypes b
where a.id=object_id('表名') and a.xtype=b.xtype and a.name='列名'
【延展】
SQL是什么意思?
SQL是英文Structured Query Language的缩写,意思为结构化查询语言。SQL语言的主要功能就是同各种数据库建立联系,进行沟通。按照ANSI(美国国家标准协会)的规定,SQL被作为关系型数据库管理系统的标准语言。SQL语句可以用来执行各种各样的操作,例如更新数据库中的数据,从数据库中提取数据等。
sql 如何查询包含某一字段的值
这种情况需要写存储过程,进行全库搜索。代码如下:
declare @cloumns varchar(40)declare @tablename varchar(40)declare @str varchar(40)declare @counts intdeclare @sql nvarchar(2000)declare MyCursor Cursor For Select a.name as Columns, b.name as TableName from syscolumns a,sysobjects b,systypes c where a.id = b.idand b.type = 'U' and a.xtype=c.xtypeand c.name like '%varchar%'set @str='张三'Open MyCursorFetch next From MyCursor Into @cloumns,@tablenameWhile(@@Fetch_Status = 0)Begin set @sql='select @tmp_counts=count(*) from ' +@tablename+ ' where ' +@cloumns+' = ''' +@str+ ''''execute sp_executesql @sql,N'@tmp_counts int out',@counts out if @counts>0 begin print '表名为:'+@tablename+',字段名为'+@cloumns endFetch next From MyCursor Into @cloumns,@tablenameEndClose MyCursorDeallocate MyCursor注意:其中“张三”为要查找的字符串,可以替换成其他的,如果查询的字符串超长,需要在定义变量时适当扩大长度。