Hi everyone
Not sure if the solution to my problem really pertains to C# or not, but here goes...
I have 2 tables in a SQL Server 2008 database; call them TypeID and TypeData. TypeID's records are unique and auto-incremented. TypeData contains a TypeID column that references to the TypeID table. TypeData can have multiple records with the same TypeID, but the rest of the data can often be different.
Reading from and updating the existing data is no problem.
The problem is that when I need to insert a new Type, I'd need to first insert a new TypeID, and then use that value (an int) to create the data in TypeData.
Is there a way (using SQL syntax or otherwise) to get, from the database, the value that it just inserted?
If it's not clear so far, here is an example:
TypeID's columns: TypeID(int), TypeDescription(nvarchar(256))
TypeData's columns: TypeID(int), ..., MoreData(int)
Inserting into TypeID:
"INSERT INTO TypeID VALUES ("SomeDescription");"
Then the database takes care of incrementing TypeID so that it's unique, but I need to know what that TypeID is. I can't just reference TypeDescription, because it's not necessarily unique.
Any help would be "muy apreciada" (much appreciated)
Not sure if the solution to my problem really pertains to C# or not, but here goes...
I have 2 tables in a SQL Server 2008 database; call them TypeID and TypeData. TypeID's records are unique and auto-incremented. TypeData contains a TypeID column that references to the TypeID table. TypeData can have multiple records with the same TypeID, but the rest of the data can often be different.
Reading from and updating the existing data is no problem.
The problem is that when I need to insert a new Type, I'd need to first insert a new TypeID, and then use that value (an int) to create the data in TypeData.
Is there a way (using SQL syntax or otherwise) to get, from the database, the value that it just inserted?
If it's not clear so far, here is an example:
TypeID's columns: TypeID(int), TypeDescription(nvarchar(256))
TypeData's columns: TypeID(int), ..., MoreData(int)
Inserting into TypeID:
"INSERT INTO TypeID VALUES ("SomeDescription");"
Then the database takes care of incrementing TypeID so that it's unique, but I need to know what that TypeID is. I can't just reference TypeDescription, because it's not necessarily unique.
Any help would be "muy apreciada" (much appreciated)