I want to be able to have a bunch of different create table scripts saved and stored seperately.
To build the entire database I would have a master .sql file that calls all the scripts in order so that all the foreign keys in the tables are created in the correct order.
I could then also make a script to delete the entire table structure by dropping them all in the reverse order.
Is there a way to do this?
Using the obscure
r:SQLCMD command:Say your create scripts are
createT1.sqlandcreateT2.sqlthen your master .sql file would be something like:This syntax works in SSMS as well, as long as you enable SQLCMD mode, see Editing SQLCMD Scripts with Query Editor. Also the
dbutilsqlcmdlibrary supports the:rextension if you want to embed this in your application.