在桌子下面:
CREATE TABLE Persons (
ID int NOT NULL,
ModifiedDate datetime,
FirstName varchar(50),
LastName varchar(50),
EMail varchar(30),
PhoneNumber varchar(15),
PRIMARY KEY (ID)
);
答案 0 :(得分:2)
您可以编写如下查询:
INSERT INTO Persons(ModifiedDate, FirstName, LastName, EMail, PhoneNumber)
SELECT
CURRENT_TIMESTAMP - INTERVAL FLOOR(RAND()* 31536000) SECOND, -- random datetime up to -1 year
CHAR(FLOOR(RAND() * 26)+ ASCII('A')), -- random character between A-Z
CHAR(FLOOR(RAND() * 26)+ ASCII('A')),
CHAR(FLOOR(RAND() * 26)+ ASCII('a')), -- random character between a-z
CHAR(FLOOR(RAND() * 10)+ ASCII('0')) -- random character between 0-9
FROM any_table_with_1000_rows
LIMIT 1000
任何具有1000行的表都可以使用。如果没有,则可以将一个具有 n 行的表自身联接起来,以获得 n 2 行。
答案 1 :(得分:1)
一种简单的方法是使用为此目的而设计的https://www.mockaroo.com/。创建所需的列,然后选择SQL作为输出。它将使您成为一个不错的脚本。
您还可以创建一个Excel电子表格来生成SQL查询,但这很耗时
答案 2 :(得分:1)
BEGIN
DECLARE @RowCount int = 1000,
@Index int = 1
WHILE (@Index <= @RowCount)
BEGIN
INSERT INTO Persons (ID, ModifiedDate, FirstName, LastName, EMail, PhoneNumber)
VALUES (@Index, getdate(), 'FirstName' + CAST(@Index AS varchar(10)), 'LastName' + CAST(@Index AS varchar(10)), 'EMail' + CAST(@Index AS varchar(10)), CAST(@Index AS varchar(10)))
SET @Index += 1
END
END