SqlServer批量產生資料的方法

來源:互聯網
上載者:User

DECLARE @i SMALLINT
SET @i = 1
WHILE (@i <=10000)
BEGIN
INSERT INTO prvflat_stuinfo_part(stuid,identitycard,stuname,stucode,sex,region)
VALUES(newid(),'330727198209193511','ckj'+'@i',@i,'1','5105')
SET @i = @i + 1
END
GO

在SQL Server中使用32全球唯一碼(GUID)可用newid來擷取。

insert into [User](id,name,sex,password)values(newid(),'xp','1','1234')

其中id資料列要求是36位char型或Uniqueidentifier 型
以下內容來自SQL Server線上說明

可以包含對 GUID 資料類型的引用,該資料類型用於儲存通用唯一識別碼。在更新查詢和插入源查詢中可以調用 newid( ) 函數,以產生新的 GUID 儲存在資料庫內。

建立選取查詢時,允許對 GUID 類型列執行的唯一操作是基於等於(= 和 <>)的比較。

下面是另一種複雜的方法

DECLARE @i BIGINT
DECLARE @max BIGINT
DECLARE @flatsign char(6)
SET @i = 1
SET @flatsign = '5101'
SET @max = 50000

WHILE (@i <=@max)
BEGIN
insert into prvflat_stuinfo
(stuid ,schid,identitycard,stuname,unitivecode,sex,birthday,flatsign)
values(newid(),newid(),
convert(varchar(6),'330727')+convert(varchar(4),@flatsign)+convert(varchar(8),REPLICATE('0',8 - len(RTRIM(LTRIM(@i)))))+convert(varchar(8),@i),
'chenkejun'+CONVERT( CHAR(9), @i ),convert(varchar(8),
REPLICATE('0',8 - len(RTRIM(LTRIM(@i)))))+convert(varchar(8),@i),
'M','2008-08-08',@flatsign)
SET @i = @i + 1
END

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.