tags:

views:

72

answers:

3

hi people i am new at php and wondering what does int(4) mean in creating this table. thanks for helping.

CREATE TABLE mytable(
name VARCHAR (50),
age INT(4),
email VARCHAR (50)
);
+1  A: 

The code you have posted is no PHP, but a SQL statement for creating a database table called mytable with three columns - name, age and email. The statement also has the date types of the different columns, so the database system can know how to store and retrieve them.

Int is a data type in the database - an integer (whole number).

What it means depends on the database you use - in SQL Server the 4 specifies the field precision. However, this will always be the size of an int in SQL Server. It can holdvalues between -2,147,483,648 and 2,147,483,647.

If MySQL, it means the display width of the field.

Oded
ok thanks, meaning that the number can be how long??
newBRO
@newBRO - answer updated with more information.
Oded
If the OP is using MySQL then it is not the size in bytes.
James McNellis
-2147483648 to 2147483647
WReach
Can the downvote please explain?
Oded
@James McNellis - The OP has not specified DBMS. I have updated my answer to be more specific.
Oded
According to the SQL Server documentation, the (4) specifies precision, not length, so it has effectively the same meaning as in MySQL (though, I haven't used SQL Server extensively to know for sure).
James McNellis
+3  A: 

If you are using MySQL, it is the display width of the integer. You can find this sort of information in the MySQL user manual:

For example, INT(4) specifies an INT with a display width of four digits.

James McNellis
+1  A: 

It depends entirely on your RDBMS: there is no standard meaning. Most will simply ignore it, or treat it as a display hint (like MySQL).

Piet Delport