Mike
Mike

Reputation: 857

Writing a Stored Procedure for UI testing

I have a web application for which I have been loading data manually (Some SQL inserts statements) for testing purposes. So every time I load data with different values. I thought of creating a Stored Procedure but even in Stored Procedure whoever is loading the data for testing has to change the values. Not sure if I am thinking the right way.

For instance, this is what I have right now:

INSERT INTO DOCUMENT_SET (DOCUMENT_SET_TRANSACTION_ID, MDATA_ATTRB, MDATA_VALUE, CREATED_TIME, LAST_MOD_TIME, ISACTIVE) VALUES 
(212019, 'SOURCE', 'M1', getDate(), getDate(), 1); 

So I insert above script around 10 times with different values for one transaction. For another transaction, I have to insert this again 10 times with different values.

Now if I create a stored procedure:

Create Procedure Transaction
As
Begin
    INSERT INTO esg.DOCUMENT_SET_TRANS_MDATA (DOCUMENT_SET_TRANSACTION_ID, MDATA_ATTRB, MDATA_VALUE, CREATED_TIME, LAST_MOD_TIME, ISACTIVE) VALUES 
(212019, 'SOURCE', 'M1', getDate(), getDate(), 1); 

    9 more times with different values for one transaction
End

So for another transaction, someone has to change the values anyways then what is the benefit of writing a procedure in this situation?

Thanks

Upvotes: 0

Views: 189

Answers (1)

Joe Stefanelli
Joe Stefanelli

Reputation: 135789

Stored procedures can accept input parameters.

Create Procedure [Transaction]
    @id int, 
    @attrb varchar(10),
    ...
As
Begin
    INSERT INTO esg.DOCUMENT_SET_TRANS_MDATA 
    (DOCUMENT_SET_TRANSACTION_ID, MDATA_ATTRB, MDATA_VALUE, CREATED_TIME, LAST_MOD_TIME, ISACTIVE) 
    VALUES 
    (@id, @attrb, ...);
...

Then, when you call the procedure,

EXEC [Transaction] @id = 212019, @attrb = 'source', ...

Upvotes: 2

Related Questions