Solved

Webmatrix, working with StarterSite.sdf

Posted on 2011-09-24
2
1,122 Views
Last Modified: 2012-05-12
Hello experts!

I have two tables:

1. ONE
index, int, primary key, is identity

2. TWO
index, bigint, primary key, is identity

I want to add foreign key and connect these two tables via index field.

The problem is: these two fields are of different type.
1. Looks like I cannot change the type of the index field.
2. Looks like I can delete index field and the add another index field, problem is: I cannot make this field "is identity".

Is there any way I can solve my problem?
Is there any editor to open "StarterSite.sdf" and make some more advanced changes there?

Thank you

panJames
0
Comment
Question by:panJames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
Daniel_PL earned 500 total points
ID: 36594582
How would you like to connect these two tables? Would you like to have foreign key in table ONE referencing table TWO or otherways?
After addition of new column all values in new column will be NULL. Then you'll need to update those rows with values from referenced table.
See followinf example.
 
USE tempdb;
GO
CREATE TABLE ONE
(
[index] INT IDENTITY(1,1),
CONSTRAINT PK_ONE_index PRIMARY KEY ([index]));
GO
CREATE TABLE TWO
(
[index] BIGINT IDENTITY(1,1),
CONSTRAINT PK_TWO_index PRIMARY KEY ([index]));
GO

INSERT INTO ONE DEFAULT VALUES
GO 100

INSERT INTO TWO DEFAULT VALUES
GO 1000

ALTER TABLE ONE
ADD
[index_TWO] BIGINT;
GO
ALTER TABLE ONE
ADD CONSTRAINT FK_index_TWO FOREIGN KEY ([index_TWO]) REFERENCES TWO([index]);
GO

UPDATE ONE 
SET ONE.index_TWO = TWO.[index]+1
FROM TWO JOIN ONE
ON TWO.[index] = ONE.[index];
GO

SELECT * FROM ONE;

DROP TABLE ONE;
GO
DROP TABLE TWO;
GO

Open in new window

0
 

Author Comment

by:panJames
ID: 36594931
How can I use this code in webmatrix?

Has it got any sql editor?

Thank you

panJames
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question