I'm having problems figuring out how to insert a row into my database. I have an experiment table which has the following columns
CREATE TABLE [dbo].[Experiment] (
[ExperimentId] INT IDENTITY (1, 1) NOT NULL,
[Experiment] VARCHAR (100) NOT NULL,
[Account] VARCHAR (100) NOT NULL,
[Profile] VARCHAR (100) NOT NULL,
[Property] VARCHAR (100) NOT NULL,
[BucketId] INT NULL,
CONSTRAINT [PK_Experiment] PRIMARY KEY CLUSTERED ([ExperimentId] ASC),
CONSTRAINT [FK_Experiment_Bucket] FOREIGN KEY (BucketId) REFERENCES Bucket (BucketId)
);
I also have a Bucket table
CREATE TABLE [dbo].[Bucket] (
[BucketId] INT IDENTITY (1, 1) NOT NULL,
[BucketName] CHAR (1) NOT NULL,
CONSTRAINT [PK_BucketId] PRIMARY KEY CLUSTERED ([BucketId] ASC)
);
An experiment can have many buckets (A-Z), however, I'm not really sure how to insert the data. I'm assuming I have to first insert the bucket information
INSERT INTO Bucket (BucketName) VALUES (@BucketName)
then I would have to insert the data in the experiment table. But how would I get the bucket id from the bucket table when populating the experiment table? Would I just need to do a select statement? Any help would be appreciated.