Błąd podczas tworzenia tabeli.

Odpowiedz Nowy wątek
2015-06-10 17:18

Rejestracja: 5 lat temu

Ostatnio: 3 lata temu

0

Witam,

Chciałem stworzyć tabelę:

CREATE TABLE countries (
  id SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
  code CHAR(4) NOT NULL,
  united_europe TINYINT(1) UNSIGNED NOT NULL,
  name VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL
  PRIMARY KEY (id),
  UNIQUE INDEX name (name)
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci

MySQL zwrócił komunikat: Dokumentacja

#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),
  UNIQUE INDEX name (name)
)
edytowany 1x, ostatnio: somekind, 2015-06-10 21:53
Na przyszłość sam wstawiaj kod w odpowiednie znaczniki. - somekind 2015-06-10 21:53

Pozostało 580 znaków

2015-06-10 17:37

Rejestracja: 5 lat temu

Ostatnio: 4 miesiące temu

0
CREATE TABLE countries (
  id SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
  code CHAR(4) NOT NULL,
  united_europe TINYINT(1) UNSIGNED NOT NULL,
  name VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL,
  constraint pk PRIMARY KEY (id),
  UNIQUE INDEX name (name)
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci

Pozdrawiam

Pozostało 580 znaków

2015-06-11 19:04

Rejestracja: 5 lat temu

Ostatnio: 3 lata temu

0

dziekuje

co oznacza: CONSTRAINT pk PRIMARY KEY (id),
???

Mam jeszcze problem z tabela:

CREATE TABLE services (
id SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
carrier_id TINYINT(4) UNSIGNED NOT NULL,
package_id TINYINT(4) UNSIGNED DEFAULT NULL,
reference_id SMALLINT(6) UNSIGNED DEFAULT NULL,
active TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
taxrate DECIMAL(3, 2) UNSIGNED NOT NULL,
kind ENUM('basic','special','pickup','delivery','restricted','cod','custom') NOT NULL,
code VARCHAR(50) DEFAULT NULL,
name VARCHAR(255) DEFAULT NULL
PRIMARY KEY (id),
INDEX IX_services (kind, code),
CONSTRAINT FK_services_carriers_id FOREIGN KEY (carrier_id)
REFERENCES allekurier.carriers(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT FK_services_packages_id FOREIGN KEY (package_id)
REFERENCES allekurier.packages(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT FK_services_references_id FOREIGN KEY (reference_id)
REFERENCES allekurier.references(id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci;

MySQL zwrócił komunikat: Dokumentacja

#1067 - Invalid default value for 'name'

edytowany 2x, ostatnio: d4rqu, 2015-06-11 19:17

Pozostało 580 znaków

2015-06-11 20:21

Rejestracja: 5 lat temu

Ostatnio: 4 miesiące temu

0
co oznacza: CONSTRAINT pk PRIMARY KEY (id),
???

Klucz główny możesz zdefiniować albo

id int primary key,
inne kolumny..

lub poprzez:

CONSTRAINT pk PRIMARY KEY (id),
CREATE TABLE services (
  id SMALLINT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
  carrier_id TINYINT(4) UNSIGNED NOT NULL,
  package_id TINYINT(4) UNSIGNED DEFAULT NULL,
  reference_id SMALLINT(6) UNSIGNED DEFAULT NULL,
  active TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
  taxrate DECIMAL(3, 2) UNSIGNED NOT NULL,
  kind ENUM('basic','special','pickup','delivery','restricted','cod','custom') NOT NULL,
  code VARCHAR(50) DEFAULT NULL,
  name VARCHAR(255) DEFAULT NULL,
  constraint pk1 PRIMARY KEY (id),
  INDEX IX_services (kind, code),
  CONSTRAINT FK_services_carriers_id FOREIGN KEY (carrier_id)
    REFERENCES allekurier.carriers(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT FK_services_packages_id FOREIGN KEY (package_id)
    REFERENCES allekurier.packages(id) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT FK_services_references_id FOREIGN KEY (reference_id)
    REFERENCES `allekurier.references`(id) ON DELETE RESTRICT ON UPDATE RESTRICT
)
ENGINE = INNODB
CHARACTER SET utf8
COLLATE utf8_general_ci;
edytowany 1x, ostatnio: Mikajlo8, 2015-06-11 20:22

Pozostało 580 znaków

Odpowiedz

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0