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('表名')