MySQL:Tabellen: Unterschied zwischen den Versionen

Aus Alexander's Wiki
(Die Seite wurde neu angelegt: „<source lang=sql> CREATE TABLE tbname ( id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(255) NOT NULL, visible BOOLEAN NOT N…“)
 
 
(2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 17: Zeile 17:
   FOREIGN KEY (id)
   FOREIGN KEY (id)
   REFERENCES othertbname(id);
   REFERENCES othertbname(id);
</source>
== ALTER ==
<source lang="SQL">
ALTER TABLE verkn MODIFY COLUMN code VARCHAR(255);
</source>
== Zeilennummerierung ==
z.Z. muss man das zweimal ausführen, aber ...
<source lang="SQL">
SELECT DISTINCT
@num := @num +1 AS position,
spalte1,
spalte2,
spalte3,
AS x, @num :=0
FROM tabelle
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;