Use test--Using the database test (if not, you need to create a new one)
----1. Create a new users table
CREATE TABLE Users (
UId int primary key identity (.),
UName varchar () NULL,
Usex bit null default (1),
UPWD varchar () NULL,
Uemail varchar (+) NULL,
Upwdfindone nvarchar () null,
Upwdfindtwo nvarchar () null,
Upwdfindthree nvarchar () null,
UPwdfindanswer1 nvarchar () null,
UPwdfindanswer2 nvarchar () null,
UPwdfindanswer3 nvarchar () null,
ucity varchar () NULL,
ubirthyear int NULL,
Ubirthmonth int NULL,
Ubirthday int NULL,
Uscore int NULL,
Uregistertime datetime NULL Default (GETDATE ()),
Uregisterip varchar (+) NULL
)
GO
----2. Loop inserts random data into the users table
DECLARE @s INT--Cycle start
DECLARE @n INT--year
DECLARE @y INT--month
DECLARE @r INT--Day
DECLARE @h INT--When
DECLARE @f int--min
DECLARE @m INT--seconds
DECLARE @mm INT--MS
DECLARE @t varchar (30)--Registration time
DECLARE @address varchar (10)--Address
DECLARE @email varchar (20)--Email
DECLARE @xb INT--Gender
DECLARE @xm varchar (20)--Name
DECLARE @ma varchar (20)--Password
DECLARE @mq1 varchar (20)--Password question 1
DECLARE @mq2 varchar (20)--Password question 2
DECLARE @mq3 varchar (20)--Password question 3
DECLARE @mqa1 varchar (20)--Password answer 1
DECLARE @mqa2 varchar (20)--Password Answer 2
DECLARE @mqa3 varchar (20)--Password Answer 3
DECLARE @bn INT--year of birth
DECLARE @by INT--Birth Month
DECLARE @br INT--Birthday
DECLARE @fs INT--Fractions
DECLARE @ip1 int--IP address 1th paragraph
DECLARE @ip2 int--IP address 2nd paragraph
DECLARE @ip3 int--IP address 3rd paragraph
DECLARE @ip4 int--IP address 4th paragraph
DECLARE @ip varchar (--IP) address
Set @s=1--setting the start of a loop
while (@s<1000)--Set the end of the loop
Begin
DECLARE @id varchar (10)
Set @id =cast (@s as varchar (10))
Begin--Registration time
Set @n=1990+abs (Checksum (NEWID ()))% (2014-1990+1)
Set @y=1+abs (Checksum (NEWID ()))% (12-1+1)
Set @r=1+abs (Checksum (NEWID ()))% (31-1+1)
if (@y=2)--The current month is February
Begin
if ((@n%4=0 and @n%100 <>0) or @n%400=0)--Leap year judgment
Set @r=1+abs (Checksum (NEWID ()))% (29-1+1)
Else
Set @r=1+abs (Checksum (NEWID ()))% (28-1+1)
End
Else
Begin
if (@y%4=0 or @y%6=0 or @y%9=0 or @y%11=0)--4, 6, 9, November up to 30 days
Set @r=1+abs (Checksum (NEWID ()))% (30-1+1)
End
DECLARE @yy varchar (5)
Set @yy =cast (@y as varchar (5))
if (@y<10)
Set @yy = ' 0 ' +cast (@y as varchar (5))
DECLARE @rr varchar (5)
Set @rr =cast (@r as varchar (5))
if (@r<10)
Set @rr = ' 0 ' +cast (@r as varchar (5))
Set @h=1+abs (Checksum (NEWID ()))% (23-1+1)
Set @f=1+abs (Checksum (NEWID ()))% (59-1+1)
DECLARE @ff varchar (5)-min, for formatting minutes
Set @ff =cast (@f as varchar (5))
if (@f<10)
Set @ff = ' 0 ' +cast (@f as varchar (5))
Set @m=1+abs (Checksum (NEWID ()))% (59-1+1)
DECLARE @miao varchar (5)-seconds, for formatting seconds
Set @miao =cast (@m as varchar (5))
if (@m<10)
Set @miao = ' 0 ' +cast (@m as varchar (5))
Set @mm =1+abs (checksum (NEWID ()))% (999-1+1)
Set @t=cast (@n as varchar (5)) + '-' [email protected]+ '-' [email protected]+ ' +cast (@h as varchar (5)) + ': ' [email protected] + ': ' [email protected]+ ': ' +cast (@mm as varchar (5))
DECLARE @time datetime
Set @time =convert (datetime,@t)
End
Begin-City and mailbox
if (@s%2=0)
Begin
Set @xb =0
Set @[email protected]+ ' @qq. com '
Set @address = ' Guangzhou '
End
Else
Begin
Set @xb =1
Set @[email protected]+ ' @msn. com '
Set @address = ' Berlin '
End
if (@s%11=0)
Begin
Set @[email protected]+ ' @nas. com '
Set @address = ' Strasbourg '
End
if (@s%22=0)
Begin
Set @[email protected]+ ' @skyweb. com '
Set @address = ' Campinas '
End
if (@s%33=0)
Begin
Set @[email protected]+ ' @gly. com '
Set @address = ' Xiamen '
End
if (@s%14=0)
Begin
Set @[email protected]+ ' @bl. com '
Set @address = ' Dalian '
End
if (@s%15=0)
Begin
Set @[email protected]+ ' @hpjx. com '
Set @address = ' Hangzhou '
End
if (@s%16=0)
Begin
Set @[email protected]+ ' @rgm. com '
Set @address = ' Wuhan '
End
if (@s%27=0)
Begin
Set @[email protected]+ ' @tf. com '
Set @address = ' Chengdu '
End
if (@s%58=0)
Begin
Set @[email protected]+ ' @fj. com '
Set @address = ' Lijiang '
End
if (@s%39=0)
Begin
Set @[email protected]+ ' @px. com '
Set @address = ' Lyon '
End
End
Begin--Name, gender, password question, password answer, etc.
Set @xm = ' uname ' [email protected]
Set @ma = ' upwd ' [email protected]
Set @mq1 = ' Upwdfindone ' [email protected]
Set @mq2 = ' upwdfindtwo ' [email protected]
Set @mq3 = ' Upwdfindthree ' [email protected]
Set @mqa1 = ' Upwd1answer ' [email protected]
Set @mqa2 = ' Upwd2answer ' [email protected]
Set @mqa3 = ' Upwd3answer ' [email protected]
Set @bn =1980+abs (checksum (NEWID ()))% (1995-1980+1)
Set @by =1+abs (checksum (NEWID ()))% (12-1+1)
Set @br =1+abs (checksum (NEWID ()))% (31-1+1)
if (@by =2)--The current month is February
Begin
if (@bn%4=0 and @bn%100 <>0) or @bn%400=0)--Leap year judgment
Set @br =1+abs (checksum (NEWID ()))% (29-1+1)
Else
Set @br =1+abs (checksum (NEWID ()))% (28-1+1)
End
Else
Begin
if (@by%4=0 or @by%6=0 or @by%9=0 or @by%11=0)--4, 6, 9, November up to 30 days
Set @br =1+abs (checksum (NEWID ()))% (30-1+1)
End
Set @fs =11+abs (checksum (NEWID ()))% (150-11+1)
End
Begin--IP Address
Set @ip1 =1+abs (checksum (NEWID ()))% (254-1+1)
Set @ip2 =1+abs (checksum (NEWID ()))% (254-1+1)
Set @ip3 =1+abs (checksum (NEWID ()))% (254-1+1)
Set @ip4 =1+abs (checksum (NEWID ()))% (254-1+1)
Set @ip =cast (@ip1 as varchar (5)) + '. ' +cast (@ip2 as varchar (5)) + '. ' +cast (@ip3 as varchar (5)) + '. ' +cast (@ip4 as varchar (5))
End
Begin-Execute SQL statement
Insert into users (Uname,usex,upwd,uemail,upwdfindone,upwdfindtwo,upwdfindthree,upwdfindanswer1,upwdfindanswer2,
Upwdfindanswer3,ucity,ubirthyear,ubirthmonth,ubirthday,uscore,uregistertime,uregisterip)
Values
@xm, @xb, @ma, @email, @mq1, @mq2, @mq3, @mqa1, @mqa2, @mqa3, @address, @bn, @by, @br, @fs, @t, @ip
)
End
Set @s+=1
End
----3. Check to see if the data has been successfully added
--select * from users
SQL Server new test data