SQL备份

CREATE
    TABLE test.user
    (
        id INT NOT NULL AUTO_INCREMENT,
        name VARCHAR(255) NOT NULL,
        password VARCHAR(255) NOT NULL,
        age INT,
        doubleValue DOUBLE,
        createDate TIMESTAMP NULL,
        PRIMARY KEY (id)
    )
    ENGINE=MyISAM DEFAULT CHARSET=utf8

 

CREATE
    TABLE test.group
    (
        id INT NOT NULL AUTO_INCREMENT,
        groupid INT,
        groupname VARCHAR(255) NOT NULL,
        PRIMARY KEY (id)
    )
    ENGINE=MyISAM DEFAULT CHARSET=utf8

 

 update user set createdate=now();

 

 select sysdate(),now(),current_timestamp(); //结果一样

 2010-08-10 19:03:56 2010-08-10 19:03:56 2010-08-10 19:03:56

 

 

 

CREATE PROCEDURE procedure_user_insert(IN size int)
begin
     DECLARE myIndex int default 0;
     DECLARE max_id int DEFAULT 1;
    select max(id) into max_id from user;
    select max_id;
repeat
    insert into user(id,name,password,createdate) values (max_id+1, concat('name_',(max_id+1)) , "pass123" , now());
    set myIndex = myIndex + 1;
    set max_id = max_id + 1;
until (myIndex>=size) end repeat;
end

call procedure_user_insert(5)

 

 

 

 

 

你可能感兴趣的:(sql)