2016-10-08 4 views
-1

meinen Code importieren:Fehler im Code MySQL-Datenbank während

CREATE TABLE IF NOT EXISTS `friends` (
    `Id`   INT(10) NOT NULL AUTO_INCREMENT, 
    `providerid` INT(10) NOT NULL AUTO_INCREMENT, 
    `requestid` INT(10) NOT NULL AUTO_INCREMENT, 
    `status`  BINARY(1) NOT NULL, 
    PRIMARY KEY (`Id`) 
); 

CREATE TABLE IF NOT EXISTS `messages` (
    `Id`   INT(255)     NOT NULL AUTO_INCREMENT, 
    `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, 
    PRIMARY KEY (`Id`) 
); 


CREATE TABLE IF NOT EXISTS `users` (
    `Id`     INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
    `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', 
    PRIMARY KEY (`Id`) 
); 

Fehler: # 1064 - Sie haben einen Fehler in Ihrer SQL-Syntax; das Handbuch , die für die richtige Syntax zu Verwendung in der Nähe von 'CREATE TABLE IF NOT EXISTS messages ( Id int (255) NOT NULL AUTO_INCREMENT' in Zeile 8

so zu Ihrer MySQL-Server-Version entspricht plz help mir den Code zu korrigieren ...

Danke

+0

nur der Primärschlüssel kann b e autoincrement – Jayvee

+0

Dies könnte Ihnen helfen. http://stackoverflow.com/questions/25349126/how-can-i-set-the-default-value-of-a-field-as-0000-00-00-000000 –

Antwort

0

es gibt einige Fehler in Ihrem Skript.

1) gibt man nur autoincrement Schlüssel sein kann, und es mu st als Schlüssel

2) Rechtschreibung mistable in dritter Abfrage von STANDARD in

NULL für NICHT

in der 3. Abfrage für unten Feld und fehlenden NULL verwendete zweimal
`email` varchar(45) NOT NULL DEFAULT '', 

3) DEFAULT-Schlüsselwort definiert werden

`authenticationTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 

RICHTIG query: -

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

CREATE TABLE IF NOT EXISTS `messages` (
    `Id` int(255) NOT NULL AUTO_INCREMENT, 
    `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 , 
    PRIMARY KEY (`Id`) 
); 


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