Programmatically copy indexes from one table to another in SQL Server
Basically the exact same question as in this question: How to copy indexes from one table to another in SQL Server , BUT, how do I do it programmatically in T-SQL, given a source table name and destination table name? I.e. without knowing what table up front. I can copy the basic structure SELECT TOP (0) * INTO [BackupTable] FROM [OriginalTable] But that doesn't copy indexes, constraints, triggers etc I ideally would like a stored proc that looks something like: spCloneTableStructure @ExistingTableName, @NewTableName That copies the columns, primary keys and indexes Anything like that exist?