SQL Server Objects
What is the right order in which we should create SQL Server objects? (This is for the installer order)?
I assume that the right order i开发者_开发知识库s
- Schemas
- Tables
- Views
- Functions
- SPs
But however, I am confused, what if a View references a function? And, what if a function references a View?
There's no "generic" order in which you can create objects (you missed e.g. a CHECK constraint on a table that may use a function). If you want it 100% right, you need to analyse your specific set of database objects and ensure that they're created in an appropriate order, by analysing the individual dependencies.
As a more straightforward example, views can access table-valued functions. But table-valued functions may be based on views. So doing all of either first wouldn't always work.
Stored procedures can be created quite early in the process, thanks to Deferred Name Resolution. This is the only positive thing to be said for it.
精彩评论