Have you ever wanted to create a copy of a database table, programmatically?

Could be a part of a stored procedure as a temporary table, or just a quick way of duplicating structure and constraints of the original one.

If so, this Transact-SQL script maybe what you’re looking for.

This T-SQL first generates a new table with the same fields as the source table and after that adds the constraints with a dynamic SQL query.

Leave a comment