Is there a “poor man's” alternative to RedGate for scripting out entire database schema? [closed]

夙愿已清 提交于 2019-12-02 18:16:49
BoltBait

Run SQL Server Management Studio, right click on the database and select Script Database as > Create to > file

That's for SQL Server 2005. SQL Server 2000 Enterprise Manager has a similar command. Just right-click on the database > All Tasks > Generate Scripts.

EDIT: In SQL Server 2005, you can select "Database" in the object explorer pane and select several databases in the details pane. Then, right-click on your selection and "Script Database as > Create to > file". This will cause it to put them all into one script and it will include all tables, keys, stored procedures, and constraints.

So, I assuming that you cannot install SQL Server Management Studio. Not even the free version. If this is a onetime thing, I would install the red gate tools. The trial version is fully functional for 14 days. Do your work, then uninstall. You might also check out http://www.xsqlsoftware.com/, they have similar functions as Red Gate. If your database is small, then they have a free option for you. I also like http://www.apexsql.com/. Use the trial of one of these and then try again to convince your boss to buy one.

In addition to the above answers, I'd like to suggest that (for future projects, at least) you don't have you master database design in the database itself.

One way to achieve this is to either simply maintain your database tables, procedures etc as 'CREATE' scripts from day one, and devise a master script that will pull all of the individual scripts together for deployment to a database of your choosing.

A more sophisticated solution is to use something like Visual Studio Database Edition (Probably too pricey, if your comments are anything to go by) which allows you to treat each database object as a node in a project, whilst still allowing the whole thing to be deployed with a few clicks.

The explanation of both of these options is over-simplified, as there are a lot of other issues - versioning, data migration etc - but the main principle is the same.

Once you've extracted your script - using one of the other answers - you may want to consider using this script as the basis for your 'master'.

Just keep the 'design' out of the database - that's purely for 'implementations'.

Try to think of the process as similar to developing code - the source and the binaries are kept separate, with the latter being generated from the former.

I have used this program from CodeProject successfully many times before. Not only does it script out the schema, it can (optionally) script out all the INSERT statements you will need for recreating the database.

I've used it against SQL Server 2000 in the past. Obviously if you have a million rows in a table it might not be a good idea to script out the contents but it's a really neat tool actually to make a series of SQL scripts to replicate a database.

If it is one-off operation and you do not fancy ordering the object scripts yourself just download a free trial version of RedGate SQL Compare.

It is 14 days full working version so it will do the entire job for you – it is completely legitimate solution. And you will have all the scripts for the future use with your manual scripting. Anyway I am pretty sure that if you find out how handy the tool is you will buy it in some later stage and that is what they probably hope for by offering fully working trial. It somehow worked in that way in my case.

Just be aware that once the trial expires it affects all the tools so make sure to make the most of it.

Michael Lang, when you right-click on the database and choose to create a script, there are several options boxes that you will need to click in order for everything to be generated. 2005 is much easier in this respect, but 2000 can do this, you just need to select the proper options.

If you're looking for a command line version, Sql Server Hosting Toolkit has worked for me in the past.

Microsoft Database Publishing Wizard (in Visual Studio 2008).

As you mentioned in SQL Server 2000 the command to use is:

While in Enterprise Manager select the database you want to script objects from and then Right Click and select All Tasks -> Generate SQL Scripts...

While in the Options Pane it is handy to select option Create one file per object it that way you can store each object in source control separately.

So then whenever you do some updates on a tableA you can check it out in source control to let others know that you work on it and the after you finish you can script that single object and save check it in.

To script a single object you can you the same option All Tasks -> Generate SQL Scripts... and then select just that one object.

The only problem with that approach is when you want to restore the complete database you need to take care of dependent objects in the sense that the top level object must be restored before the ones dependent on them.

Ironically when you script the whole database to one file the objects are not ordered in terms of dependency but rather based on the creation date. That leads to errors when you try to use it to restore the complete DB.

We ended up creating batch file that would create each object separately calling "osql "

And that all worked pretty well at that time

Now we use SQLCompare Pro and it safes us from or that hassle, but if you do not make release frequently you can live without it.

LarryF

The others are correct, but in order to create a full database from scratch, you need to create a 'device' in SQL before you run the create tables, and procedures scripts...

Use ADODB, since just about every (if not every) Windows box has it installed to execute the script.

Hell, you could even write a vbScript that executes to build your entire database. Any domain tables you have, you need to remember to turn on the identity insert before you add the items to the DB.

I'm open to source code sharing if you need it. I had to write the very same thing a couple years ago, and ended up with 3 scripts, one that created the device, then the tables, then the procedures/triggers and domain data. I wrote the code to parse the default script and allow the user to name his own database, and logins, etc.. You may not have to go that far.

Hope this helps at all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!