Created
March 2, 2026 10:20
-
-
Save MarkPryceMaherMSFT/dcb8e1f0a52ca0df4602baf65fd0bef7 to your computer and use it in GitHub Desktop.
Harden a System Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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