You are on page 1of 1

At this point, we need to determine what our stored procedure will do, and the most sensible

order of operations. Ideally, we want to collect data as efficiently as possible, accessing system
views only when needed and only collecting data for the parameters provided. In the spirit of
optimization, we’ll refrain from using iteration as much as possible, instead opting for dynamic
SQL, XML, or list generation, rather than WHILE loops or cursors.

Here is a basic outline of what we want to do, and the order we’ll want to accomplish it in:

1. Validate data as we process parameter values and determine the work we need to do.
2. Collect metadata from system views as discussed in our previous article:
a. Schemas
b. Tables
c. Columns
i. Ordinal positions
ii. Column length
iii. Column precision
iv. Column scale
v. Collation
vi. Nullable?
vii. Identity?
1. Identity seed
2. Identity increment
viii. Computed?
1. Computed column definition
ix. Sparse?
x. Default constraint?
1. Default constraint definition
d. Foreign keys
e. Check constraints
f. Indexes
i. Primary Keys
g. Triggers
h. Extended properties
3. Iterate through our table list, ensuring we generate the CREATE statements in a logical
order.
4. Generate CREATE scripts using the metadata collected above.
5. Print or select the results, based on the @Print_Results parameter.

You might also like