Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,I have a table, Alert, that is made up of three entries as shown belowwhich come from other tables.Table Alert-------------RoomID - (int)PK. This a foreign key from room table EventTypeID - (int)PK. This is foreighn key from EventType tableRegionID - (int)PK. THis is foreign key from Region tableTable EventType-------------------EventTypeID - (int) PKEventDescription - (nVarChar)Table Room--------------RoomID -(int) PKDimensions - (nchar) . .Table Region---------------RegionID - (int) PKRegionDescription -(nvarchar)I am relatively new to database programming and i am having trouble building the query to input an entry into the Alert table. I am having trouble because the entries are ID values from other tables.What information do I need to be able to add entries to the Alert table?How do I construct the query?Thanks In advanceMacca
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-05-03 : 06:28:55
Region, Room and Event are linked togather using the Alert Table, so you require the information about how they are linked togather.. and their ids.. and then insert them in the Alter Table. you must be linking them from the front end application so pull the id of each primary table and insert them in the Alert table. Now for pulling out the records from the Alert table, you need to learn the concepts of Join. Take a look in book online for Joins. Its always better, when you post over here, post same sample data so that it gets easy for understanding.. If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them.
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2006-05-03 : 06:34:08
you have to insert into Region, EventType & Room table first before inserting into Alert tableExample :
insert into Region(RegionID, RegionDescription)values (1, 'aaa')insert into EventType (EventTypeID, EventDescription)values (10, 'bbb')insert into Room (RoomID, Dimentions)values (100, 'ccc')insert into Alert(RoomID, EventTypeID, RegionID)values (100, 10, 1)