Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.