Jump to content

@@@@@@@@ Sql Help @@@@@@@@@


Recommended Posts

Posted

nenu primary key create chesthuna kuda naku e error vasthundhii....

After passing "Primary Key creation" it is going for foreign key creation.......


[b]Begin Tran[/b]

[b]Alter table dbo.OwnerPart[/b]
[b]Add ownerSupplierCode ownersupplier default '' not null[/b]


[b]Alter table dbo.OwnerPartUnassigned[/b]
[b]drop constraint FK_OwnerPartActions_OwnerPart[/b]

[b]Alter table dbo.PartXref[/b]
[b]drop constraint FK_PartXref_OwnerPart[/b]

[b]Alter table dbo.OwnerPart[/b]
[b]drop constraint PK_OwnerPart[/b]

[b]Alter table dbo.OwnerPart[/b]
[b]Add constraint PK_OwnerPart PRIMARY KEY([ownerCode],[ownerPartCode],[ownerPartRevision],[ownerSupplierCode])[/b]

[b]ALTER TABLE dbo.OwnerPartUnassigned [/b]
[b]ADD CONSTRAINT FK_OwnerPartActions_OwnerPart FOREIGN KEY([ownerCode], [ownerPartCode], [ownerPartRevision])[/b]
[b]REFERENCES dbo.OwnerPart ([ownerCode], [ownerPartCode], [ownerPartRevision])[/b]
[b]--ON UPDATE CASCADE[/b]
[b]--ON DELETE CASCADE[/b]



[b]ALTER TABLE [dbo].[PartXref] ADD CONSTRAINT [FK_PartXref_OwnerPart] FOREIGN KEY([ownerCode], [ownerPartCode], [ownerPartRevision])[/b]
[b]REFERENCES [dbo].[OwnerPart] ([ownerCode], [ownerPartCode], [ownerPartRevision])[/b]
[b]ON UPDATE CASCADE[/b]
[b]ON DELETE CASCADE[/b]


execute([color=#ff0000] 'select ownerSupplierCode from dbo.OwnerPart[/color]

[color=#ff0000]Update OwnerPart[/color]

[color=#ff0000]SET OwnerPart.ownerSupplierCode=PartXref.ownerSupplierCode[/color]
[color=#ff0000]From OwnerPart, PartXref[/color]
[color=#ff0000]Where[/color]
[color=#ff0000]PartXref.ownerCode = OwnerPart.ownerCode[/color]
[color=#ff0000]And PartXref.ownerPartCode = OwnerPart.ownerPartCode[/color]
[color=#ff0000]And PartXref.ownerPartRevision = OwnerPart.ownerPartRevision[/color]

[color=#ff0000]Select onwnerSupplierCode from dbo.OwnerPart'[/color])

Rollback

Error:-

Msg 1776, Level 16, State 0, Line 19
There are no primary or candidate keys in the referenced table 'dbo.OwnerPart' that match the referencing column list in the foreign key 'FK_OwnerPartActions_OwnerPart'.
Msg 1750, Level 16, State 0, Line 19
Could not create constraint. See previous errors.

Posted

sql ayithe kastam baa.
poni ademaina sinnaga unda ante adhi .
all i can do is taduni paiki lepadam..
sorry

Posted

[quote name='zerokool1290' timestamp='1318965819' post='3004392']
sql ayithe kastam baa.
poni ademaina sinnaga unda ante adhi .
all i can do is taduni paiki lepadam..
sorry
[/quote]

ponile ba...nuvvaina paiki lepav......thnx...

Posted

naaku sakkaga DBA ne raadu developing ante [img]http://i43.tinypic.com/9jhqw1.gif[/img]

Posted

[quote name='demo' timestamp='1318966697' post='3004503']
help
nuvu PK ki FK reference sariga ichi undaka povachu....
[/quote]


FK ki PK reference kavali ba.......deeni gurinchi nuvvu matladuthundhi ayithe...na doubt kuda adhe....

antha correct gane vundhi.....extra one column tappa....

Posted

naku kuda anta telvadu...first table lo check chesko avi correct ga PK assign ayava leda ani and then the next table try chesi chudu for FK..
e lopala evarina experts vaste adagachu..[quote name='Jeedeelu' timestamp='1318966878' post='3004523']


FK ki PK reference kavali ba.......deeni gurinchi nuvvu matladuthundhi ayithe...na doubt kuda adhe....

antha correct gane vundhi.....extra one column tappa....
[/quote]

Posted

[quote name='Jeedeelu' timestamp='1318966878' post='3004523']


FK ki PK reference kavali ba.......deeni gurinchi nuvvu matladuthundhi ayithe...na doubt kuda adhe....

antha correct gane vundhi.....extra one column tappa....
[/quote]

nuvvu PK lo 4 columns pina create chesi, FK lo matram 3 columns e reference chesav kada...that must be wrong..
endukante... if the primary key is a set of columns (a composite key), then the foreign key also must be a set of columns that corresponds to the composite key.

Posted

[quote name='pandugadu999' timestamp='1318972520' post='3004999']

nuvvu PK lo 4 columns pina create chesi, FK lo matram 3 columns e reference chesav kada...that must be wrong..
endukante... if the primary key is a set of columns (a composite key), then the foreign key also must be a set of columns that corresponds to the composite key.
[/quote]

Ya add chesa...ayina gani error isthundhii...

Alter table conflict ani.....

×
×
  • Create New...