There are a lot of options that allow the end user to programatically generate DDL in SQL Server (2000 and 2005). But what could be a reason to programatically generate the DDLs? Well, one of the reasons is that you can schedule database builds and do version control of your schema that way. Another one could be to write up a script that helps in taking a copy of the database schema from one instance and clone the schema on the another instance.
In SQL Server 2000, one can use SQL-DMO API to generate the DDLs - pretty simple to do also…just requires a simple VB code and you can then chose to wrap it with a fancy UI. One can also use the scptxfr.exe utility that ships with SQL Server 2000 and use that to automate the generation of the DDLs. There are a lot of options that this utility provides that can be used.
In SQL Server 2005, there is a new function called object_definition() that can be used to generate the object definition (such features have existed in Oracle and DB2 for quite some time). This function can be used to generate the definition of all the objects in the schema besides the tables and the referential integrity fixes. A simple script that gets these object id’s from the sys.objects table can be written which then loops through the list and generates the definitions of those objects and dumps them into an output file. One can also use the SMO API to write one’s own code to do this work –> this replaces the SQL-DMO API.
In addition to these, there are separate tools in the market that allow the generation of the DDLs (in case you want to just generate them and not automate the generation using scripting): Enterprise Manager/Query Analyzer (SQL 2000), Management Studio (SQL 2005), DB Ghost (from Innovartis), QALite (from Rac4SQL) are some of the utilities that you can use.

