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

  • Home
  • SEARCH
  • 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 8559703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:06:53+00:00 2026-06-11T16:06:53+00:00

I have a SQL Server 2008 database that I want to copy and create

  • 0

I have a SQL Server 2008 database that I want to copy and create a new database (with the a different name) on the server with. I am not concerned with maintaining data, the new database can be created with no data for starters. What I am looking to do is the following:

  • Create the new database maintaining structure of old database
  • Set the name of the new database
  • Change all varchar and char datatypes to nvarchar and nchar
  • Change all text datatypes to nvarchar(MAX)

As an aside, I have 2 more questions which are not part of my task but would like to consider the following:

  • How can I upgrade the sql server database to sql server 2012
  • Is there any preparatory work I need to carry out on the database to ensure I can easily upgrade it?
  • 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-11T16:06:54+00:00Added an answer on June 11, 2026 at 4:06 pm

    This really is a combination of multiple questions.


    QUESTIONS 1 AND 2

    • Create the new database maintaining structure of old database
    • Set the name of the new database

    The simplest backup command would be:

    BACKUP DATABASE dbname TO DISK = 'C:\some folder\dbname.bak' WITH INIT;
    -- or WITH INIT, COMPRESSION if you are on Enterprise or Developer
    

    Now to restore this as a different database, you need to know the file names because it will try to put the same files in the same place. So if you run the following:

    EXEC dbname.dbo.sp_helpfile;
    

    You should see output that contains the names and paths of the data and log files. When you construct your restore, you’ll need to use these, but replace the paths with the name of the new database, e.g.:

    RESTORE DATABASE newname FROM DISK = 'C:\some folder\dbname.bak'
      WITH MOVE 'dbname' TO 'C:\path_from_sp_helpfile_output\newname_data.mdf',
      MOVE 'dbname_log' TO 'C:\path_from_sp_helpfile_output\newname_log.ldf';
    

    You’ll have to replace dbname and newname with your actual database names, and also C:\some folder and C:\path_from_sp_helpfile_output\ with your actual paths. I can’t get more specific in my answer unless I know what those are.


    Here is a full repro:

    CREATE DATABASE [DB-A];
    GO
    
    EXEC [DB-A].dbo.sp_helpfile;
    

    Partial results:

    name     fileid filename
    -------- ------ ---------------------------------
    DB-A     1      C:\Program Files\...\DB-A.mdf
    DB-A_log 2      C:\Program Files\...\DB-A_log.ldf
    

    Now I run the backup:

    BACKUP DATABASE [DB-A] TO DISK = 'C:\dev\DB-A.bak' WITH INIT;
    

    Of course if the clone target (in this case DB-B) already exists, you’ll want to drop it:

    USE [master];
    GO
    IF DB_ID('DB-B') IS NOT NULL
    BEGIN
      ALTER DATABASE [DB-B] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
      DROP DATABASE [DB-B];
    END
    GO
    

    Now this restore will run successfully, giving you a copy of DB-A renamed as DB-B:

    RESTORE DATABASE [DB-B] FROM DISK = 'C:\dev\DB-A.bak'
      WITH MOVE 'DB-A'     TO 'C:\Program Files\...\DB-B.mdf',
           MOVE 'DB-A_log' TO 'C:\Program Files\...\DB-B_log.ldf';
    

    QUESTIONS 3 AND 4

    • Change all varchar and char datatypes to nvarchar and nchar
    • Change all text datatypes to nvarchar(MAX)

    Refactoring is a major pain, especially if some of these columns participate in constraints. You can build a very basic script this way, but you will need something much more industrial strength to deal with all of these variables. This assumes all the columns are nullable and don’t participate in constraints.

    DECLARE @sql NVARCHAR(MAX) = N'';
    
    SELECT @sql += '
      ALTER TABLE ' + 
      QUOTENAME(OBJECT_SCHEMA_NAME(c.[object_id])) 
      + '.' + QUOTENAME(OBJECT_NAME(c.[object_id]))
      + ' ALTER COLUMN ' + QUOTENAME(c.name) + ' '
      + CASE t.name WHEN N'text' 
         THEN N'nvarchar(max)' 
         ELSE N'n' + t.name + '(' + RTRIM(c.max_length) + ')'
      END + ';'
    FROM sys.columns AS c
    INNER JOIN sys.types AS t
    ON c.user_type_id = t.user_type_id
    WHERE c.system_type_id IN (35, 167, 175)
    AND OBJECTPROPERTY(c.[object_id], 'IsMsShipped') = 0;
    
    PRINT @sql;
    -- EXEC sp_executesql @sql;
    

    You can use the PRINT output to verify the first 8K of the script, and when you think it looks good, uncomment the EXEC.

    You’ll want to rebuild all of your indexes once you’re done.

    That said, scripting the database as Tony suggested (or using a tool like Red Gate’s SQL Compare – or one of its many alternatives – against an empty database) is probably going to much easier, particularly if some of these columns participate in constraints – which may need to be dropped and re-created in order to change the types.


    QUESTIONS 5 AND 6

    • How can I upgrade the sql server database to sql server 2012
    • Is there any preparatory work I need to carry out on the database to ensure I can easily upgrade it?

    You can’t upgrade just a single database on a 2008 instance. You either upgrade in place or you set up a new instance (as Tony described) and then migrate your database (preferably using backup / restore – many folks will tell you to detach / attach but that is far less safe). Preparatory work you should do include:

    • running the SQL Server 2012 Upgrade Advisor
    • ensuring none of your databases have compatibility level 80 or less

    And after the upgrade you’ll want to:

    • set the compatibility level to 110
    • update all statistics
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2008 Database running on Express. I want to copy
We have a SQL Server 2008 database that has stored procedures to handle reads/writes/etc.
I have an SQL Server 2008 database with a table that has a column
We have a SQL Server 2008 R2 Enterprise a database that is populated with
I have a few columns in an SQL server 2008 R2 database that i
I have an MS SQL Server 2008 database where I store places that serve
I have an application that accesses a sql server 2008 database. The server and
I have a database that I have created using SQL Server Developer 2008. I
A have a database on MS-SQL Server 2008 that is growing a lot, year
I have a database on SQL Server 2008. I have an ASP.NET application that

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.