Say I already created my database but forgot to save the sql commands do create it.
How could I reverse engineer the code from an already existing database?
I'm using Microsoft SQL Server Express 2008.
Say I already created my database but forgot to save the sql commands do create it.
How could I reverse engineer the code from an already existing database?
I'm using Microsoft SQL Server Express 2008.
Your RDBMS comes with some sort of "dump" tool that will give you the structure and content of your database, in the form of SQL statements.
You can do this pretty easily by using SQL Server Management Studio (SSMS) - it's available for free if you don't already have it installed.
That will create the necessary scripts to recreate your database.
To script out all the tables in your database:
Here's a link for the 2008 version SSMS Express 2008
As others have mentioned, if you have SQL Management Studio (you should, it's free as part of SQL Server Express). Fire it up, connect to your instance then expand the Database tree.
Right click on your database and select Tasks->Generate Scripts.. Click next, then Next again (which selects all objects in the database by default), pick an output option (defaults as "Save to File"), click next and voila!
If you also want to script the data as well as the schema, in the "Set Scripting Options" window, click on the Advanced button, scroll down to "Types of data to script" (just above the Table/View Options header) and select "schema and data".
[Edit] Tested - The Generate Scripts option exists and works in the (free) 2008 R2 edition of SSMS. See the link in my comment below for the URI for the R2 version.