Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Primary key violation in SQL

$
0
0

This is a bit of an odd one. Below is the code and then I will give some background.

Text
insert into occupation select g.state, o.codetype, o.code, o.codetitle from (select state from geog where areatype='01' and state<>'32') g cross join (select * from occupation where state='00') o 

My occupation table has four columns; state, codetype, code, and codetitle. It has a compound primary key (stfips, codetype, and code). At present I have 49,000 rows with only state values of 00 and 32. There is no published data set for the other 53 state values. So, I thought that I could use the code above to create new values for the states not coded 00 or 32. Below is an example of this so as to give concreteness.

getting the error shown in the last code section. Does not make any sense that I would get this error due to the fact that there are no...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>