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 1058407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:01:23+00:00 2026-05-16T18:01:23+00:00

I’m working on a few ASP.NET MVC projects which all require database functionality. Unfortunately,

  • 0

I’m working on a few ASP.NET MVC projects which all require database functionality. Unfortunately, my hosting provider only gives me two SQL Server databases to work with, so I want to put the tables of multiple projects into a single database.

However, some of my tables are similarly named, so I might run into some issues. Thus, I’m trying to find a way to change the names of all the tables so that they reflect what application they belong to.

Currently, I have the following tables in Project A:

  • Table1
  • Table2

In Project B, I have these tables:

  • Table1
  • Table2

I would like to combine the tables into a single database:

  • ATable1
  • ATable2
  • BTable1
  • BTable2

My Questions

  1. How can I automatically add a prefix to the names of all of the tables inside of a SQL Server database?
  2. Is it possible to have LINQ to SQL automatically map Table1 from my code into ATable1 or BTable1 (depending on what application it is)?
  • 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-05-16T18:01:24+00:00Added an answer on May 16, 2026 at 6:01 pm

    Put the tables in separate schemas, e.g.

    create schema ProjectA;
    create schema ProjectB;
    create table ProjectA.Table1 (...);
    create table ProjectA.Table2 (...);
    create table ProjectB.Table1 (...);
    create table ProjectB.Table2 (...);
    

    I haven’t tested this myself, but I would be very surprised if LINQ to SQL (and any other ORM for that matter) didn’t store and correctly make use of the schema names.

    If you write your own SQL commands manually, be aware that you have to quote the schema name on all objects unless it is the default schema for your current database user. This could cause a problem if (a) you have only been allocated one SQL Server login, and (b) you have a lot of existing SQL.

    To move existing tables into a new schema, e.g. tables in dbo into ProjectA:

    alter schema ProjectA transfer dbo.Table1;
    alter schema ProjectA transfer dbo.Table2;
    

    To do an automated rename, you could write a simple loop:

    declare objectsCursor cursor local fast_forward for
        select o.name as objectname, s.name as schemaname
        from sys.objects as o
        inner join sys.schemas as s on o.schema_id = s.schema_id
        -- Alter these filters depending on what you want to convert
        where s.name = 'dbo'
        and o.type = 'U'
    declare @objectname sysname, @schemaname sysname, @sql nvarchar(max)
    open objectsCursor
    fetch next from objectsCursor into @objectname, @schemaname
    while @@fetch_status = 0 begin
        select @sql = N'alter schema ProjectA transfer ' + quotename(@schemaname) + '.' + quotename(@objectname)
        execute (@sql)
        fetch next from objectsCursor into @objectname, @schemaname
    end
    close objectsCursor
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in

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.