Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server trigger
hello friends please help i have these two table dbo.carInfo and dbo.Record
 
the first table dbo.carInfo contains fields
has these fields
id
plateNo
plateCity
plateColor
ownerFullName
mobile
and the second table dbo.Record has these fields
id
plateNo
plateCity
plateColor
location
date
tax
mobile
 
Now what i want to ask is that. in those two table there are some common fields
the first table already has all values in the fields. now i want to do some thing like that whenever i want to insert a new record to the second table if some vallues of these two table are equal automatically fetch the mobile data from the first table to the second table.
 
please help me and do it for me please i really need it
Posted 9-Nov-12 3:42am
hardi24269
Edited 9-Nov-12 7:05am
Maciej Los158.6K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your database is not normalized properly. There should never be this kind of duplication in data. A much better model would look like this.
dbo.Car
   id
   plateNo
   plateCity
   plateColor
   ownerFullName
   mobile
dbo.Record
   id
   carId (foreign key to dbo.Car)
   location
   date
   tax
   mobile
Now when you insert data, you only insert it in one place and data integrity is maintained automatically.
 
When you want record data for a car the query is simple.
SELECT * 
  FROM Car
       INNER JOIN Record ON Record.CarId = Car.Id
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100