생성12

발행: (2025년 12월 4일 오전 06:48 GMT+9)
2 min read
원문: Dev.to

Source: Dev.to

단일 실행 스크립트

다음 T‑SQL 스크립트는 DBVisualizer, isql 또는 기타 도구에서 작동합니다.
INTERNTIMESTAMP 열을 포함하는 모든 사용자 테이블에 대해 최근 45 일 동안 추가된 행 수를 반환합니다.

스크립트

/* -------------------------------------------------------------
   ONE SINGLE EXECUTION – works in DBVisualizer / isql / any tool
   Shows rows from last 45 days for every table that has INTERNTIMESTAMP
   ------------------------------------------------------------- */

declare @sql nvarchar(8000)   -- use nvarchar if your ASE supports it (15.7+)
        -- or varchar(8000) on very old versions

select @sql = ''

/* Build the big UNION ALL query */
select @sql = @sql + 
       'select ''' + o.name + ''' as table_name, count(*) as rows_last_45_days from ' + o.name +
       ' where INTERNTIMESTAMP >= dateadd(day, -45, getdate()) union all '
from sysobjects o
where o.type = 'U'
  and exists (select 1 from syscolumns c 
              where c.id = o.id and c.name = 'INTERNTIMESTAMP')
order by o.name

/* Safely remove the trailing '' union all '' – no negative length */
if len(@sql) > 11
   select @sql = left(@sql, len(@sql) - 11)   -- removes last 11 chars
else
   select @sql = 'select ''No tables found'' as table_name, 0 as rows_last_45_days'

/* Execute it */
exec(@sql)
go
Back to Blog

관련 글

더 보기 »

생성11

SQL에서 `@sql`이라는 `varchar(8000)` 변수를 선언하고, `@sql`에 빈 문자열을 할당한 뒤, 각 테이블 이름(`name`)에 대해 `select ' + name + ', count from ' + name + ' where INTERNTIMESTAMP >= dateadd(dd, -45, getdate())` 형태의 쿼리를 누적한다.

비교5

SQL Script sql -- 스키마 UID를 위한 변수를 선언합니다 (한 번 실행) DECLARE @uid1 int, @uid2 int SELECT @uid1 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_1' SEL...

비교4

sql -- 먼저 사용자 ID를 한 번만 가져와서 선택 사항이며 가독성을 위해 DECLARE @uid1 int, @uid2 int SELECT @uid1 = uid FROM sysusers WHERE name = 'GLOBAL_COMET_US_1' SELE...