MySQL:Tabellen

Aus Alexander's Wiki
Zur Navigation springen Zur Suche springen
CREATE TABLE tbname (
    id            INT UNSIGNED AUTO_INCREMENT,
    name          VARCHAR(255) NOT NULL,
    visible       BOOLEAN NOT NULL DEFAULT 0,
    int_value     INTEGER(10) DEFAULT NULL,
    dec_value     DECIMAL(8,2),
    created       DATETIME,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;  

ALTER TABLE tbname DEFAULT CHARACTER SET utf8 COLLATE utf8_german2_ci;

ALTER TABLE tbname ADD UNIQUE (name, visible);

ALTER TABLE tbname ADD CONSTRAINT fk_tbname_othertbname
  FOREIGN KEY (id)
  REFERENCES othertbname(id);

ALTER

ALTER TABLE verkn MODIFY COLUMN code VARCHAR(255);

Zeilennummerierung

z.Z. muss man das zweimal ausführen, aber ...

SELECT DISTINCT
 @num := @num +1 AS position,
 spalte1,
 spalte2,
 spalte3,
 AS x, @num :=0
 FROM tabelle
 WHERE bedingung;