各种类型数据库构造测试数据总结

postgresql

#create table test (id int, test int);
#insert into test SELECT generate_series(1,1000000) as key, (random()*(10^3))::integer;

create table test (id int, info text);

insert into test select generate_series(1,100000),md5(random()::text);

select count(1) from test;  --查看个数据条数

hana

DO
BEGIN
DECLARE I INTEGER;
CREATE TABLE HDBSQL_TEST.huge(ID INTEGER NOT NULL PRIMARY KEY,NAME NVARCHAR(50),ZIP NVARCHAR(20),ADDRESS NVARCHAR(100),TELEPHONE NVARCHAR(20));
FOR I IN 1..1000000 DO
INSERT INTO huge values (:I,'George W. Bush','23193','华盛顿特区宾夕法尼亚大道1600号','202-456-1112');
END FOR;
END;

dameng

BEGIN
   FOR i IN 197240..1000197240 LOOP
    INSERT INTO OTHER.EMPSALARY VALUES ('MILLER',7934,1300);
   END LOOP;

END

kingbase

create table test (id int, test int);
insert into test SELECT generate_series(1,200000) as key, (random()*(10^3))::integer;

mongodb

use test_db;
for(var i = 0; i < 10000; i++){ db.order0531.insert({a: i});};
for(i=0;i<150000;i++){ db.orderdetial.insert({
  "id":i,"name":"shenzheng","addr":"南山","date":new Date()}); };

mysql
修改mysql配置

max_heap_table_size=4000M
innodb_flush_log_at_trx_commit=0
create database helloJiu charset=utf8;
use helloJiu;

CREATE TABLE `test_innodb` (
    `id` INT (11) NOT NULL AUTO_INCREMENT,
    `user_id` VARCHAR (20) NOT NULL,
    `group_id` INT (11) NOT NULL,
    `create_time` datetime NOT NULL,
    PRIMARY KEY (`id`),
    KEY `index_user_id` (`user_id`) USING HASH
) ENGINE = INNODB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;

#创建随机字符串函数
delimiter $$
CREATE FUNCTION rand_string(n int) RETURNS varchar(255) 
begin        
  declare chars_str varchar(100) 
  default "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  declare return_str varchar(255) default "";        
  declare i int default 0;
  while i < n do        
      set return_str=concat(return_str,substring(chars_str,floor(1+rand()*62),1));
      set i= i+1;        
  end while;        
  return return_str;    
end $$
delimiter ;

delimiter $$
CREATE  PROCEDURE `insert_data`(IN n int)
BEGIN  
  DECLARE i INT DEFAULT 1;
    WHILE (i <= n ) DO
      INSERT into test_innodb (user_id,group_id,create_time ) VALUEs (rand_string(20),FLOOR(RAND() * 100) ,now() );
            set i=i+1;
    END WHILE;
END $$
delimiter ;

#调用存储过程
call insert_data(1000000);

#插入成功后, 可以快速创建其他数据表并插入大量数据
create table test_myisam engine=myisam as select * from test_innodb;

SQL server

学生表:
CREATE TABLE [dbo].[Student](
    [StudentID] [int] IDENTITY(1,1) NOT NULL,  --主键
    [Number] [varchar](15) NULL,   --学号
    [Name] [nchar](8) NULL,  --学生姓名
    [ClassID] [int] NOT NULL  --学生所在班级ID
)

插入学生数据:
declare @count int =1;
while @count < 100
begin
insert into Student select @count,'学生'+ convert(varchar,@count,15),cast(ceiling(rand() * 5) as int)
set @count = @count + 1; 
end
    原文作者:liyuanchao_blog
    原文地址: https://blog.csdn.net/mingtiannihaoabc/article/details/106984488
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞