Jump to content

[SOLVED] Table help


dink87522

Recommended Posts

I ma trying to add this table:

 

"// Create a MySQL table in the selected database

mysql_query("CREATE DOG example(

id INT NOT NULL AUTO_INCREMENT,

PRIMARY KEY(id),

name VARCHAR(30),

age INT)")

or die(mysql_error()); 

 

echo "Table Created!";"

 

and am getting the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DOG example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(' at line 1" and don't know why this is occurring.

Link to comment
https://forums.phpfreaks.com/topic/132077-solved-table-help/
Share on other sites

mysql_query("CREATE table DOG(
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
age INT(2),
PRIMARY KEY(id) )")
or die(mysql_error());

 

Your syntax was wrong for the create table, you had primary key near the top, should always be last, you did not specify a limit on an int, 2 means it can only hold 2 places 11 means 11 places etc.

 

Questions let me know.

Link to comment
https://forums.phpfreaks.com/topic/132077-solved-table-help/#findComment-686375
Share on other sites

mysql_query("CREATE table DOG(
id INT(11) NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
age INT(2),
PRIMARY KEY(id) )")
or die(mysql_error());

 

Your syntax was wrong for the create table, you had primary key near the top, should always be last, you did not specify a limit on an int, 2 means it can only hold 2 places 11 means 11 places etc.

 

Questions let me know.

 

 

I have questions ;p.

 

 

The syntax was wrong because it said CREATE DOG not CREATE TABLE DOG, not because the primary key was near the top.  The primary key declaration can be anywhere.  It can even be:

 

CREATE TABLE blah (

    some_column INT PRIMARY_KEY

);

 

 

My second question-statement (;p):  you don't have to put a limit on integers.  Infact, even when you put a limit, it will still hold past that.  An int is 32 bytes no matter what.  The limit is really just used for zerofill (although, if you put a limit and go over it, some complex joins can get screwed up because of temporary tables assuming the column's max value is the limit).

Link to comment
https://forums.phpfreaks.com/topic/132077-solved-table-help/#findComment-686424
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.