I want to create same structure of table in another table..
But it should create same table structure with all primary keys and indexes of that old table.
I tried below but it copies only columns.. not primary key nor indexes.
SELECT *
INTO dbo.NewTable
FROM dbo.ExistingTable
WHERE 1 = 2
How can I copy/clone that too?
i’m posting you a part of a script i used to create a clone of a database, i removed some parts and it’s missing FKs and indexes (but PKs are there, ignoring identity :P) but should give you a hint on how you could do it
beware: it’s not optimised since i need to run it 1 time and not on a schedule, i just made it work with my databases 😛 fix it for your needs: