初学SQL时会遇到没有示例数据库的情况,mysql官网上有几个实例数据库可供下载 链接:https://dev.mysql.com/doc/index-other.html
我这里也写了一个可定制的SQL语句生成器,生成学生信息表,学生姓名,性别,电话,分数都是随机生成的
效果:
可以设置学生名为中文还是英文,姓和名都存在数组里,可以按需更改
<!doctype html> <html> <head> <title>Database Generator</title> </head> <body> <script> var first_names_boys= ["Carl","Abner","Herman","Roman","Baron","Francis","Hardy", "Matt","Gene","Ives","Alan","Andre","Baldwin","Barnett","Cedric", "Charles","Dana","Derrick","Devin","Earl","Elmer","Felix","Frederic", "Gavin","Hale","Henry","Herbert","Ingram","Jacob","Jason","Jeffrey", "John","Ken","Kent","King","Lambert","Leo","Leopold","Levi","Lucien", "Luther","Mark","Marvin","Max","Michael","Milo","Nathan","Nick","Noah", "Osmond","Otto","Owen","Paddy","Pete","Richard","Rock","Roy","Sampson", "Solomon","Hyman","Ian","Baron","Beacher","David","Dick","Franklin", "Howar","Ingemar","Jack","Jeff","Clement","Jeremy","Les","Nigel","Hogan", "Ivan","Lambert","Nelson","Otis","Page","Payne","Quinn","Steward", "Ted","Tim","Uriah","Quentin","Nat"]; var first_names_girls= ["Alexia","Alice","Anna","Antonia","Bella", "Bertha","Camille","Candice","Cara","Carol","Cora", "Coral","Cynthia","Dana","Daphne","Darlene","Dawn","Debby", "Deborah","Delia","Denise","Diana","Dinah","Dominic","Doris","Eileen", "Elizabeth","Elsa","Elsie","Elva","Emma","Erin","Esther","Ethel","Eudora", "Eunice","Faithe","Fanny","Fay","Flora","Florence","Gemma","Gill","Gladys", "Grace","Hedy","Helen","Hermosa","Hilary","Honey","Ingrid","Irene","Jessie", "Jill","Joanna","Karen","Kay","Kitty","Lillian","Linda","Lisa","Liz","Madge", "Martina","Maxine","Mirabelle","Moira","Nancy","Nelly","Nicola","Nicole","Page", "Pearl","Prima","Regina","Rose","Sally","Salome","Selena","Sharon","Sophia","Susan", "Tina","Una","Vanessa","Venus","Vera","Yedda","Zoe"]; var last_names = ["Smith","Jones","Williams","Brown","Taylor","Davis","Wilson", "Evans","Thomas","Johnson","Smith","Johnson","Williams","Brown","Jones","Miller", "Davis","Garcia","Rodriguez","Wilson"]; var first_names_boys_chn= ["强","建国","伟","志豪","立伟","文杰","俊杰","杰伦","磊"]; var first_names_girls_chn= ["梦琪","欣怡","雅雯","雅婷","红","梅","雪","雨","芳","娜","秀英","丽","静"]; var last_names_chn = ["王","李","张","刘","陈","杨","黄","赵","吴","周","徐","孙","马","朱","胡"]; function getRandomInt(range){ return parseInt(Math.random()*10000)%range; } function getRandomFirstName(sex,isEnglish){ if(sex&&isEnglish==true){ return first_names_boys[getRandomInt(first_names_boys.length)]; } if((!sex)&&isEnglish==true){ return first_names_girls[getRandomInt(first_names_girls.length)]; } if(sex&&isEnglish==false){ return first_names_boys_chn[getRandomInt(first_names_boys_chn.length)]; } if((!sex)&&isEnglish==false){ return first_names_girls_chn[getRandomInt(first_names_girls_chn.length)]; } } function getRandomLastName(isEnglish){ if(isEnglish==true){ return last_names[getRandomInt(last_names.length)]; }else{ return last_names_chn[getRandomInt(last_names_chn.length)]; } } document.write("create table students(student_id int,first_name varchar(20),last_name varchar(20),sex int,major_id int,score tinyint,phone_number varchar(20));"); document.write("<br>"); document.write("insert into students values<br>"); var rowsCount = 10;//修改这个数字该变产生的行数 var isEnglish = true;//英文名还是中文名 var majorCount = 5;//专业个数 for(i=0;i<rowsCount;i++){ var isBoy = getRandomInt(2) && true; document.write("("); document.write(i+1); document.write(",\""); document.write(getRandomFirstName(isBoy,isEnglish)); document.write("\",\""); document.write(getRandomLastName(isEnglish)); document.write("\","); document.write(isBoy?‘1‘:‘0‘); document.write(","); document.write(getRandomInt(majorCount)+1); document.write(","); document.write(getRandomInt(60)+40); document.write(",\"1"); switch(getRandomInt(3)){ case 0: document.write(35); break; case 1: document.write(50); break; case 2: document.write(89); break; } for(j=0;j<8;j++){ document.write(getRandomInt(10)); } document.write("\")"); if(i!=(rowsCount-1)) document.write(","); else document.write(";"); document.write("<br>"); } </script> </body> </html>