- wrote:[color=blue]
> in oracle there is a '%TYPE' to reference the data type of another
> column. is there an equivalent in mysql? thank you.[/color]
- wrote:[color=blue]
> in oracle there is a '%TYPE' to reference the data type of another
> column. is there an equivalent in mysql? thank you.[/color]
I'm not sure what you are going to do with it, but the best I can think
of it describe:
what i want to do is to refer to the column's data type.
CREATE TABLE country
(
code CHAR(2)....
....
)
CREATE TABLE user
(
..
country_code country%TYPE
..
)
in this case the code's data type is permanently 2 char long but for
other fields, it would be easier if i just put '...%TYPE' so that if the
original field changes, i do not have to change the other fields that
refer to it.
- wrote:
[color=blue]
> in this case the code's data type is permanently 2 char long but for
> other fields, it would be easier if i just put '...%TYPE' so that if the
> original field changes, i do not have to change the other fields that
> refer to it.[/color]
There's nothing like that which I would know.
I got only something like 3 years of work experience in building
databases, but I have never even thought that I could have a problem
like that. Do you really change the column types in your database so
often that you really need to worry about this? Do you really have so
many references to other column types that you couldn't do that manually
if you need to change it?
If I have a reference to other table, I always use int unsigned -type. I
have never had a need to change it. Normal columns that haven't been a
reference to anywhere, sometimes need the change, but in those cases the
%TYPE wouldn't help.
- wrote:[color=blue]
> Aggro wrote:
>[color=green]
>> If I have a reference to other table, I always use int unsigned -type.[/color]
>
>
> can you rephrase this? i don't get what you mean. thanks.[/color]
Ok, your example would be this:
CREATE TABLE country
(
id int unsigned primary key;
code CHAR(2);
....
)
CREATE TABLE user
(
..
country_id int unsigned;
..
)
So, now the reference to other table is "int unsigned". And like I said,
I have never had a need to change that reference type to another.
Aggro wrote:[color=blue]
> Ok, your example would be this:
>
> CREATE TABLE country
> (
> id int unsigned primary key;
> code CHAR(2);
> ....
> )
>
> CREATE TABLE user
> (
> ..
> country_id int unsigned;
> ..
> )
>
> So, now the reference to other table is "int unsigned". And like I said,
> I have never had a need to change that reference type to another.[/color]
in this example where int is used is acceptable. but when the code is
the primary key where there can be two and three character country code
formats (e.g US and USA).
therefore, the master table will have a CHAR(2) or CHAR(3) and referring
tables will need to know the used data type. so, if mysql has a %TYPE,
it would eliminate the need for referring tables to change the data type
each time the master table's type is changed. although the search and
replace function do make life easier.
Comment