Mysql一条快速插入测试数据的sql

Mysql快速插入测试数据

真的很好用很方便,复制到sqlyogF9(执行sql的快捷点)往死里按吧!

INSERT INTO `sys_project` (
  `proj_name`,
  `dept_val`,
  `created`,
  `updated`
) 
VALUES
  (SUBSTRING(MD5(RAND()),1,10),
  (SELECT dval FROM sys_dept ORDER BY RAND() LIMIT 1),
  NOW(),
  NOW());

上面的sql的表结构是这样的:

 [sys_dept]        [sys_project]    
 
  dval----\         proj_id
           \        proj_name
            \-------dept_val        
                    created
                    updated          

(SUBSTRING(MD5(RAND()),1,10)用来产生一个长度为10的随机字符串

(SELECT dval FROM sys_dept ORDER BY RAND() LIMIT 1)用来从sys_dept表随机抽取一个dval的值作为sys_project的外键

你可能感兴趣的:(msyql)