473,378 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Inserting foreign keys

12
Hi everyone,
I have a couple tables(Customer,Car, and Reservation). Each has its own primary key(CusId, CarId, ResId) and the Reservation table contains foreign keys CusId and CarId.
I have a Reservation form that asks for the customers first and last name,the customer should already be listed in the customer table, and what kind of car they want for the reservation.
My question is how do I find the CusId and CarId keys from the information on the form to insert into the Reservation table.


Thanks
Mar 19 '07 #1
3 1540
iburyak
1,017 Expert 512MB
Hi everyone,
I have a couple tables(Customer,Car, and Reservation). Each has its own primary key(CusId, CarId, ResId) and the Reservation table contains foreign keys CusId and CarId.
I have a Reservation form that asks for the customers first and last name,the customer should already be listed in the customer table, and what kind of car they want for the reservation.
My question is how do I find the CusId and CarId keys from the information on the form to insert into the Reservation table.


Thanks
[PHP]DECLARE @CusID int, @CarID int

SELECT @CusID = CusID from Customer where FirstName = 'first_name here'
and LastName = 'last_name_here'

SELECT @CarID = CarID from Car where car = 'car_here'

INSERT INTO Reservation values (@CusID, @CarID, .......)[/PHP]
Mar 20 '07 #2
twigboy
12
awesome thanks.
Is this a stored procedure or can I just use the DECLARE keyword in the form code?


[PHP]DECLARE @CusID int, @CarID int

SELECT @CusID = CusID from Customer where FirstName = 'first_name here'
and LastName = 'last_name_here'

SELECT @CarID = CarID from Car where car = 'car_here'

INSERT INTO Reservation values (@CusID, @CarID, .......)[/PHP]
Mar 20 '07 #3
iburyak
1,017 Expert 512MB
Put it in a stored proc:


[PHP]Create proc ProcName
@FirstName varchar(50),
@LastName varchar(50),
@Car varchar(50)
AS

DECLARE @CusID int, @CarID int



SELECT @CusID = CusID from Customer where FirstName = @FirstName
and LastName = @LastName



SELECT @CarID = CarID from Car where car = @Car



INSERT INTO Reservation values (@CusID, @CarID, .......) [/PHP]
Mar 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: J Belly | last post by:
Hi, all: I'm a newbie trying to understand the concept of referential integrity and dealing with Primary and Foreign Keys. I'm sure mine is a simple problem... I've created 3 tables as...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
4
by: Greg Ofiesh | last post by:
Anyone who can help, I have two tables T1 and T2. T1 has fields K1 and F2 and T2 has fields K2 and F1. F1 is the foreign key relating to K1 and F2 is the foreign key relating to K2. My...
1
by: Vinodh Kumar P | last post by:
I understand the number of foreign keys allowed is restricted by the DBMS I use. In a general relational schema design perspective how many foreign keys a table shall have? If I have large number...
6
by: sam | last post by:
I have to import data into a empty database, that has many tables. some tables have to be inserted first than others due to the foreign keys. How do I find out the order of the tables that I...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
2
by: Ian Davies | last post by:
I have created a database with about 17 tables. I have been creating foreign keys some of which have worked but when creating others I get the message below ************************* 1005...
9
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
5
by: dos360 | last post by:
Hello, I have two tables, one is a list of activities, the other a list of participants. I want to insert one record in the activities table and then using its identity column as foreign key, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.