Enter data from query .sql to table by parts

1

I have a database dynamically attached to my asp.net mvc project, with 12 columns to fill with test data, since I do not find a software that generates exactly the data I need and the limits of each one as age, names, dates, etc. I think that a manual way to solve this problem is to fill column by column with test data that are easy to generate, and the most specific data such as dates or surnames go extracting it from other databases.

my problem: Add 1 column of 1000 data and the other columns were NULL, when I wanted to fill column 2 with their respective 1000 data, how could I tell the DB to place this data in existing records that are incomplete or with NULL space? I hope you can understand me.

  • try but create new records with column 1 empty.

    
asked by Miko 10.03.2016 в 19:55
source

2 answers

3

In SQL Server you can check which columns have NULL, with a style query

SELECT * FROM [MiTabla] WHERE [fechaingreso] IS NULL;

To update the records that have NULL, the condition is the same:

UPDATE [MiTable] SET [fechaingreso] = '2016/03/10' WHERE [fechaingreso] IS NULL;
    
answered by 10.03.2016 / 20:11
source
3

You can use rand() to generate random data

For example:

CREATE TABLE ForgeRock
    ('id' int, 'productName' varchar(700), 'description' varchar(550))
;

INSERT INTO ForgeRock
    ('id', 'productName', 'description')
VALUES
    (rand() *1000, concat('name' , rand()*1000), concat('des', rand()*1000)),
    (rand() *1000, concat('name' , rand()*1000), concat('des', rand()*1000)),
    (rand() *1000, concat('name' , rand()*1000), concat('des', rand()*1000)),
    (rand() *1000, concat('name' , rand()*1000), concat('des', rand()*1000))
;

And we're going to have something like that

productName           | description
name530.7602607931572 | des890.7861578192433
name635.8917445278651 | des594.5086410217999
name540.8141189634932 | des509.46661877396207
name96.05401297663713 | des705.5977924779037

Here is the sqlfiddle .

This method almost ensures you have unduplicated values

    
answered by 10.03.2016 в 20:29