View or build create table schema statement programmatically with T-SQL
0
votes
1
answer
684
views
Is it possible to view or build create statement for selected table?
For example SSMS has feature
Table > Script Table as > Create To > New Query Editor Window
that can generate similar statement (**without constraints though**).
But how to generate create statement with constraints programmatically with T-SQL?
There are two ways how to view a definition that might be useful for code generating
exec sp_help 'Foo'
`SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'Foo' and TABLE_NAME = 'Bar'`
But I don't want to invent a wheel. Maybe there already exist some migration script for copying the tables **with constraints** to another database, but I did not find it yet.
Any idea? 🤔
Asked by Muflix
(1099 rep)
Sep 19, 2022, 07:37 AM
Last activity: Oct 3, 2022, 05:30 PM
Last activity: Oct 3, 2022, 05:30 PM