MySQL:Tabellen: Unterschied zwischen den Versionen

Aus Alexander's Wiki
 
Zeile 25: Zeile 25:


== Zeilennummerierung ==
== Zeilennummerierung ==
z.Z. muss man das zweimal ausführen, aber ...
<source lang="SQL">
<source lang="SQL">
SELECT DISTINCT
SELECT DISTINCT
Zeile 31: Zeile 33:
  spalte2,
  spalte2,
  spalte3,
  spalte3,
  AS x
  AS x, @num :=0
  FROM tabelle
  FROM tabelle
  WHERE bedingung;
  WHERE bedingung;
</source>
</source>

Aktuelle Version vom 18. März 2014, 14:28 Uhr

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;