Create a default row to copy

runswithsizzors

Well-known member
Joined
May 11, 2005
Messages
70
Location
Northern Michigan
Programming Experience
5-10
I have a database that the first row is a default row, then when a new entry to a database is created I need to copy this row and create a duplicate row in the same table.

This stored procedure is called every time a new project is create. Each project has a default area with an area code of 1. The keys in the database is project code and area code. Single area's can be assigned to multiple projects

This is what I have and maybe it is an easy fix:

INSERT INTO project_areas (project_code, area_code, area_name, county, township, section, town, range)
SELECT @project_code, M.area_code, M.area_name, M.county, M.township, M.section, M.town, M.range
WHERE M.area_code = @area_code

The parameters of the stored procedure is the new project code and then 1 for the area code.

Is there another way to do this or am I clueless, thanks all that reply!
 
I think you should be setting default values for the columns in SQL rather than doing default row and copy. Or at least put these rules in a trigger.

I highly recommend that you have a little chat with your DBA.

If you don't mind me saying so... programmers often leave the DBA out of the picture when they do their work and that sometimes is a set back for them.
 
Thanks for the quick reply.
I realized that my where clause was not right. What I was saying select all the area codes in the database that match that variable and of course that will fail when trying to insert one line. So I added the ability to look at the original project and changed my where statement so I select the area code from the original project, thus one area code instead of a list.

Thanks again for the reply!
 
Back
Top