create database mydb; use mydb; create table mt (Id bigint identity(1,1) not null primary key, Author varchar(100) not null default '', Comment varchar(1000) not null default '', Header varchar(100) not null default '', Name varchar(100) not null default '', ISBN varchar(100) not null default 'ISBN'+ CAST(NEWID() AS VARCHAR(36)), Title varchar(200) not null default 'Title'+CAST(NEWID() AS VARCHAR(36)), Topic varchar(100) not null default 'Topic'+CAST(NEWID() AS VARCHAR(36)), ImgUrl varchar(200) not null default '', ImgSource varbinary(max) ); CREATE PROCEDURE InsertIntoMtSp AS BEGIN DECLARE @Counter INT = 2; DECLARE @MaxRecords INT = 10000000; WHILE @Counter <= @MaxRecords BEGIN DECLARE @Author varchar(100)='Author'+CAST(@Counter AS VARCHAR(10)); DECLARE @Comment varchar(100)='Comment'+CAST(@Counter AS VARCHAR(10)); DECLARE @Header varchar(100)='Header'+CAST(@Counter AS VARCHAR(10)); DECLARE @Name varchar(100)='Name'+CAST(@Counter AS VARCHAR(10)); DECLARE @ISBN varchar(100)='ISBN'+CAST(@Counter AS VARCHAR(10)); DECLARE @Title varchar(100)='Title'+CAST(@Counter AS VARCHAR(10)); DECLARE @Topic varchar(100)='Topic'+CAST(@Counter AS VARCHAR(10)); DECLARE @ImgUrl varchar(100)='ImgUrl'+CAST(@Counter AS VARCHAR(10)); INSERT INTO mt(author,comment,header,name,isbn,title,topic,imgurl) VALUES (@Author, @Comment,@Header,@Name,@ISBN,@Title,@Topic,@ImgUrl); SET @Counter = @Counter + 1; END; END; use mydb; exec InsertIntoMtSp;
DECLARE @Author varchar(100)='Author'+CAST(@StartId AS VARCHAR(10)); DECLARE @Comment varchar(100)='Comment'+CAST(@StartId AS VARCHAR(10)); DECLARE @Header varchar(100)='Header'+CAST(@StartId AS VARCHAR(10)); DECLARE @Name varchar(100)='Name'+CAST(@StartId AS VARCHAR(10)); DECLARE @ISBN varchar(100)='ISBN'+CAST(@StartId AS VARCHAR(10)); DECLARE @Title varchar(100)='Title'+CAST(@StartId AS VARCHAR(10)); DECLARE @Topic varchar(100)='Topic'+CAST(@StartId AS VARCHAR(10)); DECLARE @ImgUrl varchar(100)='ImgUrl'+CAST(@StartId AS VARCHAR(10)); INSERT INTO mt(author,comment,header,name,isbn,title,topic,imgurl) VALUES (@Author, @Comment,@Header,@Name,@ISBN,@Title,@Topic,@ImgUrl); SET @StartId = @StartId + 1; END; END;
标签:VARCHAR,exec,CAST,sql,varchar,100,StartId,DECLARE,procedure From: https://www.cnblogs.com/Fred1987/p/18652308