sqlserver查询表名
⑴ 如何在sqlserver查询中与一个表约束的其它表名
主键约束
SELECT
tab.name AS [表名],
idx.name AS [主键名称],
col.name AS [主键列名]
FROM
sys.indexes idx
JOIN sys.index_columns idxCol
ON (idx.object_id = idxCol.object_id
AND idx.index_id = idxCol.index_id
AND idx.is_primary_key = 1)
JOIN sys.tables tab
ON (idx.object_id = tab.object_id)
JOIN sys.columns col
ON (idx.object_id = col.object_id
AND idxCol.column_id = col.column_id);
唯一约束
SELECT
tab.name AS [表名],
idx.name AS [约束名称],
col.name AS [约束列名]
FROM
sys.indexes idx
JOIN sys.index_columns idxCol
ON (idx.object_id = idxCol.object_id
AND idx.index_id = idxCol.index_id
AND idx.is_unique_constraint = 1)
JOIN sys.tables tab
ON (idx.object_id = tab.object_id)
JOIN sys.columns col
ON (idx.object_id = col.object_id
AND idxCol.column_id = col.column_id);
外键约束
select
oSub.name AS [子表名称],
fk.name AS [外键名称],
SubCol.name AS [子表列名],
oMain.name AS [主表名称],
MainCol.name AS [主表列名]
from
sys.foreign_keys fk
JOIN sys.all_objects oSub
ON (fk.parent_object_id = oSub.object_id)
JOIN sys.all_objects oMain
ON (fk.referenced_object_id = oMain.object_id)
JOIN sys.foreign_key_columns fkCols
ON (fk.object_id = fkCols.constraint_object_id)
JOIN sys.columns SubCol
ON (oSub.object_id = SubCol.object_id
AND fkCols.parent_column_id = SubCol.column_id)
JOIN sys.columns MainCol
ON (oMain.object_id = MainCol.object_id
AND fkCols.referenced_column_id = MainCol.column_id)
Check约束
SELECT
tab.name AS [表名],
chk.name AS [Check约束名],
col.name AS [列名],
chk.definition
FROM
sys.check_constraints chk
JOIN sys.tables tab
ON (chk.parent_object_id = tab.object_id)
JOIN sys.columns col
ON (chk.parent_object_id = col.object_id
AND chk.parent_column_id = col.column_id)
⑵ sqlserver 查询成绩表
select (select count(1) from dbo.T_E_Employee where age >60),(select count(1) from dbo.T_E_Employee where age <60)
⑶ sqlserver字段模糊查询A表全名对应B表关键字
你好,很高兴能够给你解答问题,给一个mysql写法,
UPDATEtest_tabaaseta.g="关键字"whereEXISTS(SELECT*fromtest_tabbbWHEREa.addrLIKECONCAT('%',b.addr,'%'))
test_taba表(id,addr,g列)类似你的A表
test_tabb表(addr)类似B表
希望可以帮助到你
⑷ 如何查询一个SqlServer数据库中有哪些表格
你说的是查询数据库中表的数目吧,如果是的话
select name from sysobjects where type='u'
这样可以查询到所有的你自己创建的表
⑸ SQLserver查询语句
写个给你参考吧,select * from table 最简单的一个
select 是查找的意思
* 所有的记录
from 从那里
table 是你要查询的表
比如 你想查看一个叫做user的表的所有内容
select * from user
假设这个user 里面有 id,name 两个字段
你现在想查看这个表 有没有一个叫做 张三的这个人的信息
select * from user where name=‘张三’
或者
select * from user where name like ‘%张三%’这个是 名字中含有战三两个字的信息都会显示的
比如 张三A ,张三b或者a张三,B张三等。
⑹ sqlserver 查询 中文表名
直接
select * from 中文
即可
⑺ sqlserver 怎么根据数据表名获取所有数据
select * from 表名
⑻ 在SqlServer查询语句中能不能用变量表示表名
sqlsever没用过,但是其他数据库要是用变量表示表名,建存储过程传参是可以的
⑼ sqlserver怎么获取表的字段名
select*fromsyscolumnswhereid=object_id('表名')