?
Solved

Webmatrix, working with StarterSite.sdf

Posted on 2011-09-24
2
Medium Priority
?
1,159 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

765 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