lima-city: Webhosting, Domains und Cloud
0 Pluspunkte 0 Minuspunkte

Wie kann ich machen das das Feld "author" immer "NULL" ist wenn man etwas speichert ohne das Feld extra anzugeben. Wenn ich also

insert into item (title, date, keywords, description, content, status) values (?,?,?,?,?,?)

eingebe und das Feld "author" nicht mit angebe soll automatisch "NULL" darin stehen. Wenn ich das NOT weg mache

`author` int(10) NULL,

dann wird gar nichts gespeichert.

DROP TABLE IF EXISTS `item`;
CREATE TABLE `item` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `title` varchar(150) NOT NULL,
  `keywords` varchar(150) NOT NULL,
  `description` varchar(150) NOT NULL,
  `content` longtext NOT NULL,
  `date` int(15) NOT NULL,
  `author` int(10) NOT NULL,
  `status` int(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

In MySQL gibt es dazu das Keyword DEFAULT.

`author` int(10) DEFAULT NULL,
von (395 Punkte)