1
2 /*
3 ** sp_ddlgen
4 **
5 **
6 ** Minimalist shell sproc to drive DDL generation for base object types.
7 ** This is currently only supporting DDL generation for databases.
8 **
9 ** Parameter:
10 ** @objtype - Type of object ('database', 'table' etc.)
11 ** @objname - Name of the object
12 ** @trace - Trace leve; for internal use only.
13 {
14 */
15 create procedure sp_ddlgen(
16 @objtype varchar(30) = NULL
17 , @objname varchar(255) = NULL
18 , @trace int = NULL
19 ) as
20 begin
21 declare @retval int
22 , @baseprocname varchar(60)
23 , @procname varchar(60)
24
25 , @obj_db varchar(8)
26 , @valid_objtypes varchar(255)
27
28 select @baseprocname = 'sybsystemprocs.dbo.sp_ddlgen_'
29
30 -- Start listing the names of entities that we support.
31 , @obj_db = 'database'
32 , @retval = 0
33
34 select @valid_objtypes = "'" + @obj_db + "'"
35
36 if (@objtype IS NULL) or (@objtype = 'help')
37 begin
38 select @procname = @baseprocname + 'help'
39 exec @retval = @procname @objname, @valid_objtypes
40 return @retval
41 end
42
43 -- Validate object type, to avoid junk error-checking downstream.
44 if (@objtype NOT IN (@obj_db
45 ))
46
47 begin
48 raiserror 19194, "@objtype", @valid_objtypes
49 return 1
50 end
51
52 -- Handle NULL objname input:
53 -- . For databases, generate DDL for the current db of user.
54 --
55 if ((@objtype = @obj_db) and (@objname IS NULL))
56 select @objname = db_name()
57
58 -- Name the permission checking sub-proc for generating the DDL.
59 select @procname = @baseprocname + 'permissions'
60 exec @retval = @procname @objtype, @objname
61 if (@retval = 0) -- Check for failure in permissions checks
62 return 1
63
64 -- Name the sub-proc generating the DDL.
65 select @procname = @baseprocname + @objtype
66
67 -- Fork off control to the sub-proc, if we got the right objtype.
68 if (@objtype IN ('database'
69 --, add a new entry here in the future.
70 ))
71 begin
72 exec @retval = @procname @objname, @trace
73 end
74
75
76 return @retval
77 end -- }
78
exec sp_procxmode 'sp_ddlgen', 'AnyMode'
go
Grant Execute on sp_ddlgen to public
go