MySql CREATE TABLE代码中的语法错误 [英] Syntax error in MySql CREATE TABLE code

查看:107
本文介绍了MySql CREATE TABLE代码中的语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个表格导入XAMPP phpMyAdmin,但它说它有一些错误。



你能告诉我正确的表格吗?



这是代码:



  CREATE   TABLE   IF    EXISTS 朋友

' 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 默认
);

CREATE TABLE IF NOT EXISTS 条消息

' 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 用户

' 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 ' '
' < span class =code-string> IP' varchar 45 NOT NULL DEFAULT ' '
' port' int 10 )unsigned NOT NULL DEFAULT ' 0'
);





谢谢各位朋友。

解决方案

你好HOoman,



你的表有三个自动增量列,每列都有相同的价值,这没有有意义。



假设在这种情况下另外两个表(提供者和请求),每个都有一个存储好友ID的列是正常的value以便将提供者和请求表中的行链接到朋友行。



因为如果您将记录插入朋友,它将看起来像这样:



1,1,1,...

2,2,2,...

3,3,3,...

4,4,4,...

......等等



希望它有所帮助。


我建​​议你查看第一个表:

  CREATE    IF    EXISTS 朋友

' 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
);

您为状态指定了DEFAULT,但是您没有给出默认值或零或一个..


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:

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.

解决方案

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.


I'd suggest you look at the first table:

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


这篇关于MySql CREATE TABLE代码中的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆