MySql CREATE TABLE代码中的语法错误

编程入门 行业动态 更新时间:2024-10-27 03:31:10
本文介绍了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 ' ', ' 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代码中的语法错误

本文发布于:2023-07-22 04:08:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1184016.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语法错误   代码   MySql   CREATE   TABLE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!