'Can DB2 DDL be generated using the IBM.Data.Db2 library

I'm new to Db2 and need to generate DDL for an existing table but don't have access to any tools. Is it possible to do this through the IBM.Data.DB2 library? I can get a datareader but only the field name is available. I work in a very restrictive environment hence the no tools statement. I don't know what operating system is used on the server. I'm a c#\vb.net developer and can execute commands of type text and stored procedures; however, creating stored procedures is very limited. I've done this sort of thing with Sql's SMO library but am not well versed with IBM.Data.DB2.



Solution 1:[1]

            using (DB2Command dB2Command = new DB2Command($"SELECT * FROM {database}.{tableName}", dB2Connection))
            {
                dB2Command.CommandType = System.Data.CommandType.Text;

                using (DB2DataReader dB2DataReader = dB2Command.ExecuteReader())
                {
                    DataTable dataTable = dB2DataReader.GetSchemaTable();
                    foreach(DataRow dataRow in dataTable.Rows)
                    {
                        Console.WriteLine($"ColumnName: {dataRow.Field<string>("ColumnName")}\nColumnSize: {dataRow.Field<int>("ColumnSize").ToString()}\nNumericPrecision: { dataRow.Field<Int16>("NumericPrecision").ToString()}\nNumericScale: { dataRow.Field<Int16>("NumericScale").ToString()}\nDataType: {dataRow.Field<DbType>("ProviderType").ToString()}");
                        Console.WriteLine("");
                    }
                }
            }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Butler