Create table with relations

T

totto

Hi,
I would like to add a new tabel to an existing Access 97 database that
contains data. This should be done from a .net application via sql script.
The script should aslo add a field to one of the exitsting tabels, with a
relation to a field in the new tabel.

NewTable
NewTableID int PrimaryKey,
NewTableName string;

ExistingTable
--Existing fields--,
NewField int;

I want a one to many relation between NewTableID and NewField.

Anyone who can help me with this ?

Best regards
Totto
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In run order:

New table:

CREATE TABLE NewTable (
NewTableID INTEGER PRIMARY KEY ,
NewTableName VARCHAR(50)
)

Load data into NewTable:

INSERT INTO NewTable
SELECT * FROM OldTable

Add column to old table as Foreign Key:

ALTER TABLE ExistingTable
ADD COLUMN NewField INTEGER REFERENCES NewTable (NewTableID)

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQSKEo4echKqOuFEgEQJEXACeNojgcIq674Ml1jE64rXf98Md6kMAn1AM
Ag/oPHEEipDkCJ6jsNHMzFb5
=UDfB
-----END PGP SIGNATURE-----
 
T

Totto

Hi MGFoster,
Tanks !
Just one more question;
Is it possible to execute all the commands at once(Separated by som sign) or
do I have to excecute each command one by one ?
Totto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top