0% found this document useful (0 votes)
5 views4 pages

SQL Server Data Entry Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

SQL Server Data Entry Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Guide: Automating SQL Server Data Entry at 6 AM and 6 PM

Step 1: Create Your Table

First, create your table in SQL Server to store the state name and tag values:

CREATE TABLE MyTable (

StateName NVARCHAR(100),

Tag1 NVARCHAR(100),

Tag2 NVARCHAR(100),

Tag3 NVARCHAR(100),

Tag4 NVARCHAR(100),

Tag5 NVARCHAR(100),

Tag6 NVARCHAR(100),

Tag7 NVARCHAR(100),

Tag8 NVARCHAR(100),

Tag9 NVARCHAR(100),

Tag10 NVARCHAR(100)

);

Step 2: Write a Stored Procedure for Data Insertion

Create a stored procedure that will handle the insertion of data into the table:

CREATE PROCEDURE InsertDataIntoMyTable

AS

BEGIN

INSERT INTO MyTable (StateName, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7,
Tag8, Tag9, Tag10)

VALUES

('California', 'TagA', 'TagB', 'TagC', 'TagD', 'TagE', 'TagF', 'TagG', 'TagH',

'TagI', 'TagJ');

END;

Step 3: Use SQL Server Agent to Schedule the Task

SQL Server Agent allows you to schedule jobs to run at specific times.

Steps:

1. Open SQL Server Management Studio (SSMS).

2. Expand the SQL Server Agent in the Object Explorer.

3. Right-click on Jobs and select New Job.

Configure the Job:

1. General Tab:

- Name your job (e.g., InsertDataJob).

- Add a description if needed.

2. Steps Tab:

- Click on New to add a new step.

- Set the step name (e.g., InsertDataStep).

- Choose Transact-SQL Script (T-SQL) as the type.

- Use this command to execute the stored procedure:

EXEC InsertDataIntoMyTable;

3. Schedules Tab:

- Click on New to create a schedule.

- Set the Name (e.g., 6AM_6PM_Schedule).


- Set the frequency to Daily.

- Under Daily Frequency, specify:

- Occurs: 2 times a day.

- Start times: Enter 06:00:00 and 18:00:00.

4. Save the job.

Step 4: Enable SQL Server Agent

Ensure the SQL Server Agent is running. If it is stopped, start it:

1. In SSMS, right-click SQL Server Agent in the Object Explorer.

2. Click Start.

Step 5: Test the Job

Manually run the job to ensure everything is working:

1. Right-click on your job (InsertDataJob) under SQL Server Agent > Jobs.

2. Click Start Job at Step.

3. Check your table to verify the data has been inserted:

SELECT * FROM MyTable;

Output in the Table

At 6:00 AM and 6:00 PM, the following data will be inserted into the table:

| StateName | Tag1 | Tag2 | Tag3 | Tag4 | Tag5 | Tag6 | Tag7 | Tag8 | Tag9 |

Tag10 |

|-------------|-------|-------|-------|-------|-------|-------|-------|-------|-------|-------|

| California | TagA | TagB | TagC | TagD | TagE | TagF | TagG | TagH | TagI |

TagJ |
Summary

- Stored Procedure: Handles the insertion logic.

- SQL Server Agent Job: Schedules the stored procedure to run at 6:00 AM and

6:00 PM daily.

- Verification: Query the table to confirm the data is inserted correctly.

You might also like