SQL语句创建表并插入指定N条数据(用于测试)

CREATE TABLE [dbo].[TestTable](  
    [D_Id] [int] IDENTITY NOT NULL,  
    [D_Name] [varchar](50) NULL,  
    [D_Password] [varchar](32) NULL,  
    [D_Else] [varchar](4000) NULL,  
     CONSTRAINT [PK_TestTable] PRIMARY KEY CLUSTERED   
    ([D_Id] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]  
) ON [PRIMARY]  
GO  
DECLARE @d datetime   
SET @d=getdate()  --计时开始   
DECLARE @index INT  
SET @index = 1  
WHILE @index<5000 
BEGIN   
INSERT INTO TestTable(D_Name,D_Password,D_Else)  
VALUES('名称'+Cast(@index as varchar),'密码测试'+Cast(@index as varchar),'其他'+Cast(@index as varchar))  
SET @index=@index+1   
END  
SELECT [语句执行花费时间(毫秒)]=datediff(ms,@d,getdate()) --计时结束
/*mysql*/
DROP PROCEDURE if exists dowhile;
CREATE PROCEDURE dowhile()
 begin 
  declare i int default 0;
  start transaction;
   while i<50 do
    insert into demo(name) values(concat('s00',i)); 
    set i=i+1; 
   end while; 
  commit;
 end;

CALL dowhile();
--随机产生26个英文字符 大小写
SELECT CHAR(97+CEILING(RAND()*25))+ CHAR(65+CEILING(RAND()*25)) AS RandChar

posted @ 2012-08-23 15:17  深南大道  阅读(570)  评论(0编辑  收藏  举报