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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:47:29+00:00 2026-05-29T20:47:29+00:00

I’m reorganizing our MySQL database, changing MyISAM tables to InnoDB and setting foreign keys,

  • 0

I’m reorganizing our MySQL database, changing MyISAM tables to InnoDB and setting foreign keys, and I’m wondering if there’s a way to link the column settings also?

Example:

in my useraccount table, the user column is varchar(20). In all my other tables another user column to record who entered the record, also varchar(20).

I’m wondering how I might go about linking all those dependent user columns, like if I had to change the useraccount.user column to varchar(40), can I set all other table user columns to cascade to varchar(40) as well?

I’m sure I could use the information schema to write a PHP script to do this but I’d rather have the database modify itself without outside help if possible. Could this be done through a trigger on the schema record for the username.user column? And if so could I then also make a trigger to automatically add foreign key constraints on any new table where a ‘user’ column gets added?

seems like it should be possible but I’ll admit I don’t know MySQL well enough to go screwing around with schema tables 😉

Edit: Here is some sample SQL I wrote to find the mismatched tables

SELECT TABLE_NAME, COLUMN_TYPE
FROM information_schema.COLUMNS 
WHERE TABLE_NAME != 'user_accounts'
AND COLUMN_NAME = 'user'
AND COLUMN_TYPE != (
    SELECT COLUMN_TYPE 
    FROM information_schema.COLUMNS 
    WHERE TABLE_NAME = 'user_accounts' 
    AND COLUMN_NAME = 'user'
)

Ideally I’d like to use this information_schema result to loop through each row of the above result and ALTER the tables to change the Column Types to match the column type of user_account.user

  • 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-29T20:47:30+00:00Added an answer on May 29, 2026 at 8:47 pm

    In SQL, DDL doesn’t cascade.

    In standard SQL, you’d use domains (which MySQL unfortunately doesn’t support). Let’s say you had this PostgreSQL code stored in your version control system.

    create domain USER_DOMAIN varchar(15) not null;
    
    create table users (
      user USER_DOMAIN primary key
    );
    
    create table another_table (
      user USER_DOMAIN references users (user),
      other_column char(1) not null,
      primary key (user, other_column)
    );
    

    When the need arises, you can change one line of code in version control . . .

    create domain USER_DOMAIN varchar(20) not null;
    

    . . . dump the data, load the new schema, reload the data, and you’re done. But be warned that this can take quite a while on a huge database. (Moving the data takes the most time.)

    You can accomplish the same thing in MySQL, even though it doesn’t support the CREATE DOMAIN statement. Instead of SQL, use the m4 macro processor.

    # test.m4 -- demonstrate replacing CREATE DOMAIN with m4 macro.
    define(`USER_DOMAIN', `varchar(15) not null')dnl
    
    create table users (
      user USER_DOMAIN primary key
    );
    
    create table another_table (
      user USER_DOMAIN references users (user),
      other_column char(1) not null,
      primary key (user, other_column)
    );
    

    Then run that code through m4 as part of your makefile. m4 will replace USER_DOMAIN with ‘varchar(15) not null’.

    $ m4 test.m4
    
    create table users (
      user varchar(15) not null primary key
    );
    
    create table another_table (
      user varchar(15) not null references users (user),
      other_column char(1) not null,
      primary key (user, other_column)
    );
    

    Now changing to varchar(20) is still only a one-line change.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this
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
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.