SQL Server Batch Data Generation Method

Source: Internet
Author: User
Tags rtrim

Declare @ I smallint
Set @ I = 1
While (@ I <= 10000)
Begin
Insert into prvflat_stuinfo_part (stuid, identitycard, stuname, stucode, sex, region)
Values (newid (), '000000', 'ckj' + '@ I', @ I, '1', '20140901 ')
Set @ I = @ I + 1
End
Go

You can use the 32 guid in SQL Server to obtain the guid using newid.

Insert into [user] (ID, name, sex, password) values (newid (), 'xp ', '1', '123 ')

The ID data column must be of the 36-bit Char or uniqueidentifier type.
The following content comes from SQL Server online help

It can contain a reference to the guid data type, which is used to store globally unique identifiers. You can call the newid () function in the update query and insert Source Query to generate a new guid and store it in the database.

When creating a SELECT query, the only operation that can be performed on the guid type column is based on comparison of equal to (= and <>.

The following is another complicated method.

Declare @ I bigint
Declare @ Max bigint
Declare @ flatsign char (6)
Set @ I = 1
Set @ flatsign = '000000'
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), '000000') + 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', '2017-08-08 ', @ flatsign)
Set @ I = @ I + 1
End

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.