Solved

Webmatrix, working with StarterSite.sdf

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now