Sql Server 2008 (and probably most other versions): Management Studio has a 'generate scripts' option that can in theory script a whole database with all objects (Right click, tasks, Generate Scripts). It works OK for most things but when you use it to script all views/stored procedures/functions in a database, it generates a script that does not take account of dependencies between the objects.
e.g. If View A references Function B it won't necessarily put Function B in the script first.
It takes a long time to untangle the great long script that gets produced so that it is in an order that will run without errors.
There must be a better way. Whats the best way to get round this, preferably without spending any money?*
* (red gate ftw)