Creating Dummy Data in SQL Server

Asked 2 years ago, Updated 2 years ago, 102 views

Suppose you have a table similar to the following:

table: m_tbl

ID AreaCode
--- ---
1   0000000001
2   0000000002
3   0000000003
4   0000000021
5   0000000044
.   .
.   .
.   .
  • ID is the primary key
  • Duplicate AreaCode is acceptable
  • 500,000 data

I would like to use these data to re-register 50 billion (50,000,000,000) data while re-shifting my ID.

What kind of SQL statement would this be?

sql sql-server

2022-09-30 14:50

1 Answers

Why don't you run INSERT~SELECT~ 10 times?

INSERT INTO other (AreaCode)
SELECT AreaCode FROM m_tbl

The above is omitted with the assumption that the ID is in the IDENTITY column, but if necessary, please add it appropriately.

If you also want to write the recurring part in Transact-SQL, use the WHILE statement to:

DECLARE
    @int=1;
BEGIN
    WHILE@i<=10
        BEGIN

            INSERT INTO other (AreaCode)
            SELECT AreaCode FROM m_tbl;

            SET@i=@i+1;

        END
END


2022-09-30 14:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.