How do you programmatically generate T-SQL CREATE statements for existing indexes in a database? SQL Studio provides a "Script Index as->Create to" command that generates code in the form:
IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = N'IX_myindex')
CREATE NONCLUSTERED INDEX [IX_myindex] ON [dbo].[mytable]
(
[my_id] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
GO
How would you do this programmatically (ideally through Python)?