데이터베이스 이름은 AT입니다. 이 데이터베이스 150 테이블. 행 수와 열 수를 반환하는 문을 데이터베이스의 모든 테이블에 넣고 싶습니다.Sybase 데이터베이스의 모든 테이블에있는 행 수 열 수
SQL Server 2008의 저장소 프로 시저를 만들었지 만 Sybase 용이 스크립트를 작성하는 방법을 모르겠습니다.
데이터베이스 이름은 AT입니다. 이 데이터베이스 150 테이블. 행 수와 열 수를 반환하는 문을 데이터베이스의 모든 테이블에 넣고 싶습니다.Sybase 데이터베이스의 모든 테이블에있는 행 수 열 수
SQL Server 2008의 저장소 프로 시저를 만들었지 만 Sybase 용이 스크립트를 작성하는 방법을 모르겠습니다.
Sybase ASA에는 데이터베이스 구조에 대한 정보를 제공하는 많은 시스템 테이블이 있습니다. 관심있는 두 테이블은 SYSTABLE
(모든 테이블) 및 SYSCOLUMN
(모든 열)입니다.
나 (오히려 오래된 ASA 버전 8!)에서 작동하는 빠르고 저장 프로 시저를 사용해 보았습니다. 임시 테이블과 커서를 만들어 모든 테이블을 반복합니다. 모든 테이블에 대해 테이블 이름, 열 수 및 행 수를 임시 테이블에 삽입하고 마지막으로 반환합니다.
(힌트 :. tablefilter 당신이 여러 테이블이있는 경우, 전체 데이터베이스의 일부를 반환 할 수 있습니다)이 같은 ISQL에서
CREATE PROCEDURE Usr_TableStats(in par_tablefilter char(100))
RESULT (tablename varchar(255), number_of_cols int, number_of_rows int)
BEGIN
declare err_notfound exception for sqlstate value '02000';
declare @table_id integer;
declare @tablename varchar(100);
declare @cols integer;
declare @sql varchar(300);
declare tables no scroll cursor for select table_id, table_name from sys.systable where table_type = 'BASE' and table_name like par_tablefilter || '%' order by table_name;
create table #tablestats (
tablename varchar(100) not null,
number_of_cols int not null default 0,
number_of_rows int not null default 0
);
open tables;
LoopTables: loop
fetch next tables into @table_id, @tablename;
if sqlstate = err_notfound then
leave LoopTables
else
SELECT COUNT(column_id) INTO @cols FROM SYSCOLUMN WHERE table_id = @table_id;
set @sql= 'INSERT INTO #tablestats SELECT ''' || @tablename || ''', ' || @cols || ', COUNT(*) FROM ' || @tablename || ';';
EXECUTE IMMEDIATE WITH QUOTES @sql;
end if
end loop LoopTables;
close tables;
SELECT tablename, number_of_cols, number_of_rows FROM #tablestats;
END
전화를 :
CALL Usr_TableStats('%'); -- all tables
CALL Usr_TableStats('ADDRESS%'); -- only tables starting with ADDRESS
sys.systable 및 sys.syscolumn은 다음 정보를 제공해야합니다.
Select st.table_name,
st.count as row_count,
col_count = (SELECT count(*) FROM sys.syscolumn where table_id = st.table_id)
from SYS.SYSTABLE st where st.creator <> 0 and st.count > 0
order by st.table_name