Re: Altering Table - Adding Primary Key With References

From: Mikhail (Mikhail_at_discussions.microsoft.com)
Date: 09/04/04


Date: Sat, 4 Sep 2004 05:17:02 -0700

While attempting to execute command

ALTER TABLE Morechildren ADD PRIMARY KEY cid TAG cid REFERENCES Parents TAG id

in VFP5,VFP6,VFP9 error message "Syntax error" is generated.

!!! VFP does not support PRIMARY KEY constraint with TAG and REFERENCES
keyword's at same command. (CREATE TABLE, ALTER TABLE) !!!

For future discus pls refer example image
http://www.intell-corp.ru/img/example.jpg

"Anders Altberg" wrote:

> If you want the relation to be a one-to-one instread of one-to-many, you can
> let the primary key of the Child table be the referecing field. But you
> can't do it with the ALTER TABLE command in VFP8. You can do it in the
> CREATE TABLE command. And you can just set up the reference in the Database
> Designer window by drag-and-drop.
> These commands work:
> CREATE DATABASE Test
> CREATE TABLE Parents (id i NOT null PRIMARY KEY autoinc)
> CREATE TABLE Children (id i NOT null PRIMARY KEY REFERENCES Parents TAG id)
> CREATE TABLE morechildren (cid Integer NOT NULL )
> ALTER TABLE Morechildren ADD FOREIGN KEY cid TAG cid1 REFERENCES Parents
> TAG id
> ALTER TABLE Morechildren ADD PRIMARY KEY cid TAG cid REFERENCES Parents TAG
> id
> ALTER TABLE Morechildren ADD CANDIDATE cid TAG cid REFERENCES Parents TAG id
> CANDIDATE is a synonym for UNIQUE.
> Please note that the foreign key creation doesn't set up referential
> integrity. You have to go to RI Builder to do that.
> -Anders
>
> "Mikhail" <Mikhail@discussions.microsoft.com> wrote in message
> news:8014F7E0-D462-44A9-A58C-BC702530ED4E@microsoft.com...
> > Can i, using alter table command, add primary key, which refers to a field
> in
> > other table?
> >
> > VFP Help Citation:
> >
> > ALTER TABLE TableName1 [DROP [COLUMN] FieldName3]
> > ...
> > [ADD PRIMARY KEY eExpression3 [FOR lExpression4] TAG TagName2
> > [COLLATE cCollateSequence]]
> >
> > In CREATE TABLE a can add primary key, which refers to field in another
> > table, but can't specify TAG for field which name is longer that 10 chars
> :
> >
> > VFP Help Citation:
> >
> > CREATE TABLE | DBF TableName1 [NAME LongTableName] [FREE]
> > ( FieldName1
> > ...
> > [PRIMARY KEY | UNIQUE [COLLATE cCollateSequence]]
> > [REFERENCES TableName2 [TAG TagName1]] [NOCPTRANS])
> >
>
>



Relevant Pages

  • SQL Server confused about primary keys. So am I.
    ... We are generating a script to convert a client's database to Sql ... ALTER TABLE dbo.Categories ADD ... CONSTRAINT PK_Categories PRIMARY KEY CLUSTERED ...
    (microsoft.public.sqlserver.server)
  • Nested sort, trying again
    ... from the whole organization to shelves in a ... Users never see the primary key, only the NAMEX, ... This is the same as seeing you directory tree in Windows explorer with the name chosen as the sort key. ... ALTER TABLE IS3.LOCATIONS ...
    (comp.databases.theory)
  • Re: Altering Table - Adding Primary Key With References
    ... The CREATE TABLE command work fine. ... > let the primary key of the Child table be the referecing field. ... > can't do it with the ALTER TABLE command in VFP8. ... > ALTER TABLE Morechildren ADD FOREIGN KEY cid TAG cid1 REFERENCES Parents ...
    (microsoft.public.fox.vfp.dbc)
  • Nested sort
    ... I have a table which implements a set of locations for an organization, from the whole organization to shelves in a particular room. ... Users never see the primary key, only the NAMEX, usually as a drop down selection list, sometimes a single selection other times a multiselection. ... Users, being users, want the ability to change names and to see the names in sorted order at each level. ... ALTER TABLE IS3.LOCATIONS ...
    (comp.databases.theory)
  • Re: Alter table help
    ... alter table table_name add constraint constraint_name primary key ... > "Tom Pennington" wrote in message ... >> Okay, I'm trying to modify a tables primary key, actually, I'm trying to ...
    (microsoft.public.sqlserver.programming)

Loading