Solved

Webmatrix, working with StarterSite.sdf

Posted on 2011-09-24
2
1,099 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Caste datetime 2 57
Exchange 2016 Databse move 5 54
Server running out of memory - Something is consuming all the available memory 17 56
Mongo DB 18 41
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

776 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