Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
eplam2
Starting Member
11 Posts |
Posted - 2013-09-03 : 04:47:43
|
Say for instance I got 2 tablesSubject Table and a Student TableThe Subject Table consist of the following attributes:Subject_ID [PK], Subject_Name, Course_ID and Course_NameThe Student Table consists of the following attributes:Subject ID [FK], Students_Name, Students_bday, Students_age, Students_height and Students_weightHow can I use the INSERT function when I would like to add a row with the following details:Course_Name : BiotechnologyStudents_Name : FredStudents_bday : 01/JAN/1990Stundets_age : 54Im confused as to how to use the INSERT function for multiple tables. Could any help me out? Thanks in Advance! :)Kind Regards, Elvin |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-03 : 05:23:09
|
what should be the Subect_name, course_id for course_name "Biotechnology"?if Subject_id is IDENTITY columnDECLARE @SubjectId INT INSERT Subject (Subject_Name, Course_ID and Course_Name) VALUES( 'XXXX', 1, 'Biotechnology')SET @subjectId = SCOPE_IDENTITY(); INSERT Student (Subject ID, Students_Name, Students_bday, Students_age)VALUES(@subjectId , 'Fred', '01/JAN/1990', 54) --Chandu |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
|
eplam2
Starting Member
11 Posts |
Posted - 2013-09-03 : 08:48:16
|
There is no given Subject Name or Course ID, so that's assume as a null valueWhat does the function 'SCOPE_IDENTITY()' do? Which function in Oracle replaces it? |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-09-03 : 08:52:52
|
First clarify me some doubts1) If subject name is NULL then why you should you insert into Subject Table?2) You passed CourseName. Where do you insert that value? For what purpose you are passing CourseName? SCOPE_IDENTITY() will return the auto incremented value of SubjectID in the case of above script..whereas Oracle has sequences to have auto increment numbers...--Chandu |
 |
|
|
|
|
|
|