select s.name as TABLE_SCHEMA, t.name as TABLE_NAME, k.name as CONSTRAINT_NAME, c.name as COLUMN_NAME, ic.key_ordinal AS ORDINAL_POSITION
from sys.key_constraints as k
join sys.tables as t on t.object_id = k.parent_object_id
join sys.schemas as s on s.schema_id = t.schema_id
join sys.index_columns as ic on ic.object_id = t.object_id and ic.index_id = k.unique_index_id
join sys.columns as c on c.object_id = t.object_id and c.column_id = ic.column_id
where k.type = ‘PK’ and s.name=’fdp_bfm’
order by 1,2,3
CREATE TABLE #counts(table_name varchar(255),row_count int);
EXEC sp_MSForEachTable @command1=’INSERT #counts (table_name, row_count) SELECT ”?”, COUNT(*) FROM ?';
SELECT * FROM #counts order by 1;
再发一个可以查询数据库里面,每个表数据记录条数的SQL, 估计很少人用到这个函数