Ich habe diese drei TabellenMake Verfahren mit SCOPE_IDENTITY()
CREATE TABLE
(
FirstTableId Int primary key identity,
Something nvarchar(20)
)
CREATE TABLE SecondTable
(
SecondTableId Int primary key identity,
Something nvarchar(20)
)
CREATE TABLE Relation
(
RelationId int primary key identity,
RelationSomething nvarchar(20),
FirstTableId Int,
SecondTableId Int,
FOREIGN KEY (FirstTableId) REFERENCES FirstTable(FirstTableId),
FOREIGN KEY (SecondTableId) REFERENCES SecondTable(SecondTableId),
)
Ich schaffe diese Prozedur Daten in FirstTable und Relation einzufügen:
CREATE PROC InsertInto (@FirstTableId int)
AS
INSERT INTO FirstTable VALUES ('example')
SELECT @FirstTableId = SCOPE_IDENTITY()
INSERT INTO Relation (RelationSomething, FirstTableId, SecondTableId) VALUES ('example', @FirstTableId, 2)
I Werte von den Dropdownlists zum Beispiel Daten übergeben, und Übergeben Sie nichts für @FirstTable, weil ich erwarte, dass es SCOPE_IDENTITY() erhalten, aber ich habe Fehler wie folgt: "Muss die skalare Variable" @FirstTableId "deklarieren? Wie kann ich das lösen und es funktioniert?
Ihr Beispielcode neu das Problem nicht. – SqlZim