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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:43:35+00:00 2026-05-31T17:43:35+00:00

We have a DB with a few hundred tables that have a CHAR Code

  • 0

We have a DB with a few hundred tables that have a CHAR “Code” field used for various ressources. This code field is the primary key and foreign key for multiple tables.

We now display this code on mouseover of the ressource in our ASP.NET application and when the code is shorter than the CHAR field length, it displays white spaces. We fix this through RTRIMing (which is often overlooked).

  1. We’ll only have a few 10s to low 100s of active users so performance impact shouldn’t be that big
  2. Would there be a way to automatically drop and recreate all PK/FK constraints while converting from CHAR TO VARCHAR? I’ve looked a bit at INFORMATION_SCHEMA and it looks like it would be feasible.
  • 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-31T17:43:36+00:00Added an answer on May 31, 2026 at 5:43 pm

    In my experience char causes many problems, not only unexpected spaces in the front-end:

    • There’s logic errors when a comparison doesn’t account for the trailing spaces.
    • When you ask for the len(): does it return the length of the string including or excluding spaces?
    • char consumes more disk space than necessary. Since a primary key is included in every index for its table, this can add up to a non-trivial amount of space.

    So it’s typically a good idea to refactor from char to varchar.

    Depending on the number of tables you have, this can be quite a lot of work. You’d first have to drop every contraint that references the columns. Then you’d:

    alter YourTable alter column YourColumn varchar(50) primary key
    

    After that you would re-add constraints. You will find that it takes a lot of trying to add/remove the constraints in the right order. For example, a foreign key requires a unique constraint on the referenced column. So you’d have to drop the foreign key before the unique constraint.

    Right click database -> Tasks -> Generate Scripts would provide you with a lot of the statements for re-creating the constraints, if not always in the correct order.

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

Sidebar

Related Questions

i have a database that has a few hundred tables i need to find
I have a SQL database that has several hundred tables in it, but I
I have a php page that pulls a few hundred characters (distributed amongst 8
I have the following problem. I have a table with a few hundred thousand
And worry about it later like when I have few hundred records at least?
I have to transform a few hundred images every day in a specific way.
Suppose you have a collection of a few hundred in-memory objects and you need
I have few question in this regard When you create an internet page, does
I have few hundred rows of data in four columns (varA, varB, varC, varD).
How could I optimize this MySQL queries that is accessing two tables with more

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.