Skip to content

Instantly share code, notes, and snippets.

@MarkPryceMaherMSFT
Created March 2, 2026 10:20
Show Gist options
  • Select an option

  • Save MarkPryceMaherMSFT/dcb8e1f0a52ca0df4602baf65fd0bef7 to your computer and use it in GitHub Desktop.

Select an option

Save MarkPryceMaherMSFT/dcb8e1f0a52ca0df4602baf65fd0bef7 to your computer and use it in GitHub Desktop.
Harden a System Table
declare @list varchar(max)
declare @sql nvarchar(max)
drop table if exists sys_tables
create table sys_tables (object_id bigint, tablename varchar(50))
SELECT @list = STRING_AGG('(' + CAST([object_id] AS VARCHAR(20)) + ', ''' + CAST([name] AS VARCHAR(128)) + ''')', ',') FROM sys.tables
SET @sql = 'INSERT INTO sys_tables (object_id, tablename) VALUES ' + @list
--print @sql
exec sp_executesql @sql
select * from sys_tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment