我創建了一個插入存儲過程有兩個表所示:外鍵爲空當插入在exapmle使用存儲過程
表NameAge
CREATE TABLE [dbo].[Assignment3_NameAge]
(
userID int PRIMARY KEY IDENTITY(1,1),
Name varchar(255) NOT NULL,
Age int NOT NULL
)
表嗜好
CREATE TABLE [dbo].[Assignment3_Hobbies]
(
hobbiesID int Identity(1,1) Primary Key,
userID int Foreign Key references Assignment3_NameAge(userID),
hobbies varchar(255) NOT NULL,
)
插入存儲過程
CREATE PROCEDURE [dbo].p_Assignment3Join_ins
@Name nvarchar(100),
@Age int,
@Hobbies nvarchar(100)
AS
INSERT INTO [TABLE].[dbo].[Assignment3_NameAge]
([Name]
,[Age])
VALUES (@Name,@Age)
INSERT INTO [TABLE].[dbo].[Assignment3_Hobbies]
([Hobbies])
VALUES (@Hobbies)
問題是,當我運行存儲過程表愛好有一個空值的用戶名(外鍵)
我做錯了什麼?
你正在使用什麼類型的數據庫(MSSQL,MySQL,Oracle等)? – Aaron