2

Under what circumstances will MySQL convert types to TINYINT? I know that a BOOL or BOOLEAN type in mysql DDL will automatically be converted to TINYINT(1) for for true or false. I am analyzing a database which has a type of varchar(16) on a field in one table, and tinyint(4) on the same field on another table? E.g t1.name varchar(15) and t2.name tinyint(4) where t1.name=t2.name.

2
  • 1
    Very bad choice for a join condition. The types should be the same. Commented Sep 9, 2014 at 5:37
  • But could it be that they might be a third unkown table that perhaps joins the table tables indirectly by directly joining to t2.name e.g create table t3(id...PK, ws_connect tinyint(4), name varchar(16));? Commented Sep 9, 2014 at 5:47

1 Answer 1

1

Don't rely on implicit type conversion, do your datatype analysis manually:

First lets see what MySQL thinks as the best col-type for your data. Run a

 SELECT * FROM table PROCEDURE Analyse()

Analyse your data further by saying

 SELECT * FROM table WHERE varcharCol NOT REGEXP '^[0-9].*$'

To get all non-numeric values in varcharCol. If there are non you finally have to check value-ranges of different MySQL-types here.

Then you are ready to convert your varcharCol e.g. to TINYINT.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.