I am trying to refactor a load of spaghetti code in some SQL I've inherited. Currently it's in one massive script with loads of temp tables and and interdependencies. I want to split this out into manageable files to start to understand the dependencies and make the source code easier to manage.
I would like to be able, for example, to define a table in one file, and then import it in another that requires the table to be present to compile. E.g.
-- File 1 table defs -------------------------------
-- table definition
TABLE_1 [
create table T (id int, name varchar(20))
go
]
-- End File 1 -------------------------------------
-- File 2 -- sp_FirstProc
[INSERT TABLE_1]
create procedure sp_FirstProc
@myId int
as
begin
select * from T where id=@myId
end
---- end file -------------------------
when I run the build script it replaces the tokens in the second file with the one defined in the first to produce:
--- file created by build script--------
create table T (id int, name varchar(20))
go
create procedure sp_FirstProc
@myId int
as
begin
select * from T where id=@myId
end
--- end file created by build script--------
Any suggestions? Thanks!
I would like to be able, for example, to define a table in one file, and then import it in another that requires the table to be present to compile. E.g.
-- File 1 table defs -------------------------------
-- table definition
TABLE_1 [
create table T (id int, name varchar(20))
go
]
-- End File 1 -------------------------------------
-- File 2 -- sp_FirstProc
[INSERT TABLE_1]
create procedure sp_FirstProc
@myId int
as
begin
select * from T where id=@myId
end
---- end file -------------------------
when I run the build script it replaces the tokens in the second file with the one defined in the first to produce:
--- file created by build script--------
create table T (id int, name varchar(20))
go
create procedure sp_FirstProc
@myId int
as
begin
select * from T where id=@myId
end
--- end file created by build script--------
Any suggestions? Thanks!
Comment