tags:

views:

87

answers:

2

This is the DB Schema:

PC
- id (pri key)
- model
- name

Laptop
- id (pri key)
- model
- name

How do I get for each unique(model) laptop, how do I insert it into PC with model number + 1? (+1 because I know insert into might work but the prob I need won't be solved with insert into)

Any clue?


Elaboration:

For each unique (based on model column) Laptop record that we have, we want to create a PC record in which the model column for the PC would be +1 of the model column in laptop.

+3  A: 

+1 doesn't stop "INSERT INTO" from working:

INSERT INTO PC
    ( Model, Name )
SELECT DISTINCT Model + 1, Name
FROM Laptop
David
Just a hunch, because the question is hard to understand, but I think the OP added the +1 because they thought somehow that using the same model number would make the insert fail. I think that was a workaround and they didn't necessarily want the model number to be +1.
JohnFx
A: 

This was mentioned in the comments by jrockway and is probably your best bet if you plan to keep the 1-1 relationship of laptops to PCs with a +1 model number.

Drop the laptop table altogether and just create the following view (Assuming SQL Server):

CREATE VIEW PC
AS
SELECT  ID,Model+1 as Model, Name
FROM Laptop

This way you don't have to manage and keep two table synchronized.

JohnFx