Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:56:15+00:00 2026-06-09T15:56:15+00:00

I have three websites which uses an abstract database structure with tables like: Items,

  • 0

I have three websites which uses an abstract database structure with tables like: Items, Places, Categories, etc… and stored procedures like GetItemsByCategory, GetRelatedItems, etc… Actually im using exactly the same database structure for these 3 different websites.

From a code perspective im using the same code for all websites (except the HTML which is specific foreach one), and all the common code is in few projects used by all websites, so everytime that i detect a bug (which is in all websites) i just fix it on one place (the common part used by all) and automatically all websites get the fix.

Actually im using Asp.net MVC3 and Sql server.

Everytime i want to extend some funcionality, and i need a new table, stored procedure or something related with database, i have to do the modification in each database.

  • Do you know any approach that i could use to be able to have the same flexibility and do database modifications only one time for all websites?

  • Do you think I’m using a good approach or i should use something different in your opinion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:56:16+00:00Added an answer on June 9, 2026 at 3:56 pm

    If the databases are on a single server, you could generate the script for the procedure from Management Studio, and make sure to use the option to "check for object existence" (Tools > Options > SQL Server Object Explorer > Scripting). This will yield something like this (most importantly it produces your stored procedure code as something you can execute using dynamic SQL):

    USE DBName;
    GO
    
    SET ANSI_NULLS ON;
    GO
    
    SET QUOTED_IDENTIFIER ON;
    GO
    
    IF NOT EXISTS (...)
    BEGIN
        EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE dbo.whatever ...
        '
    END
    GO
    

    Now that you have this script, you can modify it to work across multiple databases – you just need to swipe the @statement = portion and re-use it. First you need to stuff the databases where you want this to work into a @table variable (or you can put this in a permanent table, if you want). Then you can build a command to execute in each database, e.g.

    DECLARE @dbs TABLE (name SYSNAME);
    
    INSERT @dbs(name) SELECT N'db1';
    INSERT @dbs(name) SELECT N'db2';
    INSERT @dbs(name) SELECT N'db3';
    
    -- now here is where we re-use the create / alter procedure command from above:
    
    DECLARE @statement NVARCHAR(MAX) = N'CREATE PROCEDURE dbo.whatever ...
        ';
    
    -- now let's build some dynamic SQL and run it!
    
    DECLARE @sql NVARCHAR(MAX);
    SET @sql = N'';
    
    SELECT @sql = @sql + '
      EXEC ' + QUOTENAME(name) + '.dbo.sp_executesql N''' + @statement + ''';'
      FROM @dbs;
    
    EXEC sys.sp_executesql @sql;
    

    Alternatively, you could create a custom version of my sp_msforeachdb or sp_ineachdb replacements:

    • Making a more reliable and flexible sp_MSforeachdb
    • Execute a Command in the Context of Each Database in SQL Server

    I used to use a tool called SQLFarms Combine for this, but the tool doesn’t seem to exist anymore, or perhaps it has been swallowed up / re-branded by another company. Red Gate has since produced SQL Multi Script that has similar functionality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are 5 websites in ASP.NET 2.0 which have the same code and database
I have an ASP.Net website which uses a MySQL database for the back end.
I have a .NET web application in which I am developing three separate websites
I have a website which uses SVG for an interactive client side thingamabob. I
I have an ASP.Net 4.0 website which uses SQL Server CE and EF code-first
I have a dynamic ListView which uses an ArrayAdapter . When a name is
I have an asp.net application which uses the web part framework to allow users
I have very large website which uses a lot of cookies. There are approx.
I have a .Net 3.5 website which uses windows authentication and expires the session
I have an existing PHP website which uses a considerable amount of jQuery and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.