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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:33:16+00:00 2026-05-28T23:33:16+00:00

I have inherited a database I need to work with. All the numeric fields

  • 0

I have inherited a database I need to work with. All the numeric fields have been set to bigint (without reason they are all sub 5000).

How can I programmticaly change all the columns of big int to int? Is this possible will it cause issue with any existing constraints etc?

I only want to change tables and only in the specific database I am working on.

I am using SQL Server 2008 R2

I need to do this for hundreds of fields I am looking for something that I can run once and it will do all the updates for all table fields. I want to keep any existing constraints, null status and default values.

So basically a database wide change of bigint to int without changing anything apart from the field type.

Thanks

  • 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-28T23:33:17+00:00Added an answer on May 28, 2026 at 11:33 pm

    Well, I had come across this kind of problem. I had to change int to bigint. This is harder, but possible. It is very easy to change datatype using the following statement:

    Alter table myTable alter column targetcolumn int not null

    However if your columns are involved in constraint relationship then you have to drop your constraints then alter and then recreate your constraints.

    Alter table myTable drop constraint [fkconstraintname]
    Alter table myTable alter column targetcolumn int not null
    Alter table othertable alter column targetcolumn int not null
    Alter table myTable add constraint [fkconstraintname] foreign key (targetcolumn) references othertable(targetcolumn)
    

    EDIT

    If you have a lot of constraints then changing it is a real pain in the butt. If there are a lot of tables with constraints and no extreme urge at changing don’t do it.

    EDIT

    Then you can do the following. Connect to Sql Server via Management Studio, right click on the necessary database => Tasks => Generate scripts.

    Next => Next

    Necessary window

    At that point press advanced. There will be a popup. Set Type of data to script to schema and data. Choose whatever output is comfortable for you (file, query window)? Press ok and proceed. It will produce you a complete DDL and DML, like this:

    USE [master]
    GO
    /****** Object:  Database [Zafarga]    Script Date: 02/02/2012 19:31:55 ******/
    CREATE DATABASE [Zafarga] ON  PRIMARY 
    
    GO
    ALTER DATABASE [Zafarga] SET COMPATIBILITY_LEVEL = 100
    GO
    IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
    begin
    EXEC [Zafarga].[dbo].[sp_fulltext_database] @action = 'enable'
    end
    GO
    ALTER DATABASE [Zafarga] SET ANSI_NULL_DEFAULT OFF
    GO
    ALTER DATABASE [Zafarga] SET ANSI_NULLS OFF
    GO
    ALTER DATABASE [Zafarga] SET ANSI_PADDING OFF
    GO
    ALTER DATABASE [Zafarga] SET ANSI_WARNINGS OFF
    GO
    ALTER DATABASE [Zafarga] SET ARITHABORT OFF
    GO
    ALTER DATABASE [Zafarga] SET AUTO_CLOSE OFF
    GO
    ALTER DATABASE [Zafarga] SET AUTO_CREATE_STATISTICS ON
    GO
    ALTER DATABASE [Zafarga] SET AUTO_SHRINK OFF
    GO
    ALTER DATABASE [Zafarga] SET AUTO_UPDATE_STATISTICS ON
    GO
    ALTER DATABASE [Zafarga] SET CURSOR_CLOSE_ON_COMMIT OFF
    GO
    ALTER DATABASE [Zafarga] SET CURSOR_DEFAULT  GLOBAL
    GO
    ALTER DATABASE [Zafarga] SET CONCAT_NULL_YIELDS_NULL OFF
    GO
    ALTER DATABASE [Zafarga] SET NUMERIC_ROUNDABORT OFF
    GO
    ALTER DATABASE [Zafarga] SET QUOTED_IDENTIFIER OFF
    GO
    ALTER DATABASE [Zafarga] SET RECURSIVE_TRIGGERS OFF
    GO
    ALTER DATABASE [Zafarga] SET  ENABLE_BROKER
    GO
    ALTER DATABASE [Zafarga] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
    GO
    ALTER DATABASE [Zafarga] SET DATE_CORRELATION_OPTIMIZATION OFF
    GO
    ALTER DATABASE [Zafarga] SET TRUSTWORTHY OFF
    GO
    ALTER DATABASE [Zafarga] SET ALLOW_SNAPSHOT_ISOLATION OFF
    GO
    ALTER DATABASE [Zafarga] SET PARAMETERIZATION SIMPLE
    GO
    ALTER DATABASE [Zafarga] SET READ_COMMITTED_SNAPSHOT OFF
    GO
    ALTER DATABASE [Zafarga] SET HONOR_BROKER_PRIORITY OFF
    GO
    ALTER DATABASE [Zafarga] SET  READ_WRITE
    GO
    ALTER DATABASE [Zafarga] SET RECOVERY FULL
    GO
    ALTER DATABASE [Zafarga] SET  MULTI_USER
    GO
    ALTER DATABASE [Zafarga] SET PAGE_VERIFY CHECKSUM
    GO
    ALTER DATABASE [Zafarga] SET DB_CHAINING OFF
    GO
    EXEC sys.sp_db_vardecimal_storage_format N'Zafarga', N'ON'
    GO
    USE [Zafarga]
    GO
    /****** Object:  Table [dbo].[Category]    Script Date: 02/02/2012 19:31:56 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Category](
        [CategoryId] [bigint] IDENTITY(1,1) NOT NULL,
        [CategoryName] [nvarchar](max) NULL,
    PRIMARY KEY CLUSTERED 
    (
        [CategoryId] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    /****** Object:  Table [dbo].[Product]    Script Date: 02/02/2012 19:31:56 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Product](
        [ProductId] [bigint] IDENTITY(1,1) NOT NULL,
        [Name] [nvarchar](max) NULL,
        [Price] [decimal](18, 2) NOT NULL,
        [CategoryId] [bigint] NOT NULL,
    PRIMARY KEY CLUSTERED 
    (
        [ProductId] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    /****** Object:  ForeignKey [Category_Products]    Script Date: 02/02/2012 19:31:56 ******/
    ALTER TABLE [dbo].[Product]  WITH CHECK ADD  CONSTRAINT [Category_Products] FOREIGN KEY([CategoryId])
    REFERENCES [dbo].[Category] ([CategoryId])
    ON DELETE CASCADE
    GO
    ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [Category_Products]
    GO
    

    Change all your datatypes appropriately, then run.

    As you said all your data is below 5000 rows. So there is no need to modify insert statements.

    Be ready it will take a long time.
    Hope this was useful.

    EDIT

    This will generate you a new database, so be ready to rename your original or newly created db.

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

Sidebar

Related Questions

All great stories they always start with those 4 magical words... I have inherited
I have inherited a database that has no real referential integrity at all, so
I have inherited a database that has a lot of cursors in it, and
i have inherited a database application from someone else and there are a few
I have inherited a very old database that needs some data to be updated.
I have a situation where I need to determine whether or not an inherited
I have an access database that I need to update only if my information
Okay guys I have a database I have been working on for days now.
I need some help to get this to work. It works, but i have
I have inherited a client site which crashes every 3 or 4 days. It

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.