Afeter insert trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jdavis29
    New Member
    • Jan 2012
    • 1

    Afeter insert trigger

    Hi

    I have the nex table

    CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTA MP ON UPDATE CURRENT_TIMESTA MP,
    `date_created` date DEFAULT NULL,
    `time_created` time DEFAULT NULL,
    `name` varchar(20) DEFAULT NULL,
    `password` varchar(20) DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `id` (`id`),
    UNIQUE KEY `password` (`password`),
    UNIQUE KEY `password_2` (`password`)
    ) ENGINE=InnoDB AUTO_INCREMENT= 18 DEFAULT CHARSET=latin1;


    I want to create a trigger that after i make an insert into name and passwor columns, it inserte the current date on date_created column, and the current time on time_created column.

    Please, can some one help me with this...
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    you dont need a trigger our insert query would be

    Code:
    INSERT INTO `users` (`date_created`,`time_created`,`name`,`password` 
    ) VALUES(DATE(), TIME(), 'chosen Name', password('choosen password'));
    rest will be done by your auto and defaults

    Comment

    Working...