dink87522 Posted November 10, 2008 Share Posted November 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132077-solved-table-help/ Share on other sites More sharing options...
premiso Posted November 10, 2008 Share Posted November 10, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/132077-solved-table-help/#findComment-686375 Share on other sites More sharing options...
dink87522 Posted November 10, 2008 Author Share Posted November 10, 2008 Ok thanks, although why must Primary go last? Quote Link to comment https://forums.phpfreaks.com/topic/132077-solved-table-help/#findComment-686415 Share on other sites More sharing options...
corbin Posted November 10, 2008 Share Posted November 10, 2008 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). Quote Link to comment https://forums.phpfreaks.com/topic/132077-solved-table-help/#findComment-686424 Share on other sites More sharing options...
dink87522 Posted November 10, 2008 Author Share Posted November 10, 2008 Thanks for that Corbin. Quote Link to comment https://forums.phpfreaks.com/topic/132077-solved-table-help/#findComment-686428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.