Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to create a table to Import into XAMPP phpMyAdmin but it says it has some errors.

can you tell me the correct form please?

this is the code:

SQL
CREATE TABLE IF NOT EXISTS friends
(
'Id' int (10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY ('Id'),
'providerid' int(10) NOT NULL AUTO_INCREMENT,
'requestid' int(10) NOT NULL AUTO_INCREMENT,
'status' binary(1) NOT NULL DEFAULT
);

CREATE TABLE IF NOT EXISTS messages
(
	'id' int(255) NOT NULL AUTO_INCREMENT,
	PRIMARY KEY ('id'),
	'fromuid' int(255) NOT NULL,
	'touid' int(255) NOT NULL,
	'sentdt' datetime NOT NULL;
	'read'tinyint(1) NOT NULL DEFAULT '0',
	'readdt' datetime DEFAULT NULL,
	'messagetext' longtext CHARACTER SET utf8 | NOT NULL
);


CREATE TABLE IF NOT EXISTS users 
(
	'Id' int(10) unsigned NOT NULL AUTO_INCREMENT,
	PRIMARY KEY ('Id'),
	'username' varchar(45) NOT NULL DEFAULT '',
	'password' varchar(32) NOT NULL DEFAULT '',
	'email' varchar(45) NOT NULL DEFAULT '',
	'date' datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
	'status' tinyint(3) unsigned NOT NULL DEFAULT '0',
	'authenticationTime' datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
	'userKey' varchar(32) NOT NULL DEFAULT '',
	'IP' varchar(45) NOT NULL DEFAULT '',
	'port' int(10) unsigned NOT NULL DEFAULT '0'
);


thank you friends.
Posted

Hi HOoman,

Your table has three auto increment columns, each column will have the same value, this does not make sense.

It would be normal to presume that, in this case two other tables (provider and request), would each have a column that stored the friends Id value so as to link the rows in provider and request tables to a friends row.

As it is if you insert a records into friends it will look something like this:

1,1,1,...
2,2,2,...
3,3,3,...
4,4,4,...
...etc.

Hope it helps.
 
Share this answer
 
I'd suggest you look at the first table:
SQL
CREATE TABLE IF NOT EXISTS friends
(
'Id' int (10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY ('Id'),
'providerid' int(10) NOT NULL AUTO_INCREMENT,
'requestid' int(10) NOT NULL AUTO_INCREMENT,
'status' binary(1) NOT NULL DEFAULT
);
You are specifying a DEFAULT for status but you don't give teh default value or zero or one...
 
Share this answer
 
Comments
HOoman.2012 12-Jul-15 2:06am    
dear friend, i tried, but still has some errors:

MySQL said: Documentation

#1064 - 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 ''Id' int (10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY ('Id'),
'providerid' int(10' at line 3
OriginalGriff 12-Jul-15 2:26am    
You either specify PRIMARY KEY at the end of the table definition, or as part of the line declaring the column: you have it in the middle.
Easiest way:
CREATE TABLE IF NOT EXISTS friends
(
'Id' int (10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
'providerid' int(10) NOT NULL AUTO_INCREMENT,
'requestid' int(10) NOT NULL AUTO_INCREMENT,
'status' binary(1) NOT NULL DEFAULT
);
Michael_Davies 12-Jul-15 2:52am    
Is it me or will Id, providerid and requestid all have the same value within a row?
OriginalGriff 12-Jul-15 3:08am    
Well, yes...I didn't notice that!
I think the OP is just guessing what to do rather than thinking it through...:sigh:
OriginalGriff 12-Jul-15 3:09am    
I'd suggest you add that as a separate solution - it needs addressing (and an upvote)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900