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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:15:48+00:00 2026-05-22T17:15:48+00:00

I am creating a new table by copying an existing table structure: CREATE TABLE

  • 0

I am creating a new table by copying an existing table structure:

CREATE TABLE IF NOT EXISTS `PeopleView` LIKE `People`

I then want to change the data type of all fields using a wild card:

ALTER TABLE `PeopleView` CHANGE * * VARCHAR(3) NOT NULL

Any ideas how to do this?

I can do something like:

ALTER TABLE `PeopleView` CHANGE `FirstName` `FirstName` VARCHAR(3) NOT NULL

But I need a function I can run on many different tables where the field names are all different.

Purpose: Create another table that holds values that are used to decide which columns will be shown or hidden.

PHP Solution:

mysql_query("CREATE TABLE IF NOT EXISTS `PeopleView` LIKE `People`");

$cols = mysql_query("SHOW COLUMNS FROM `PeopleView`");

$sql = "ALTER TABLE `PeopleView` ";
while($row = mysql_fetch_assoc($cols)) {
  $sql .= "MODIFY `". $row['Field'] ."` VARCHAR(3) NOT NULL, ";
}
$sql = substr($sql, 0, -2);
mysql_query($sql);

I don’t like that I have to run 3 queries to the database, surely there is a better way?

  • 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-22T17:15:49+00:00Added an answer on May 22, 2026 at 5:15 pm

    I then want to change the data type of all fields using a wild card:

    You cannot do so. The syntax will only allow you to change the field types by enumerating them and their new definition, one by one.

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

Sidebar

Related Questions

I am creating a temp table with a query like this: CREATE TEMPORARY TABLE
I'm creating a new table in a SQL Server 2008 database and I want
When I am creating a new database table, what factors should I take into
I need UNION two tables with creating new field, where 1 for first table,
I have a table that its structure is as like as follow: `id` int(10)
I am creating a new table in Microsoft SQL server 2000 by writing the
have a problem creating my new table in SqlLite3 I have created this migration
When creating a new table in a database, what is the importance of using
I was just creating a new table using MySQL Query Browser, and noticed there's
I am trying to build a dynamic forms app like wufoo . Creating new

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.