在我看来,这是一个随着sql /数据库开发一直出现的问题,但后来我对这一切都不熟悉,所以请原谅我的无知.
我有2张桌子:
CREATE TABLE [dbo].[Tracks]( [TrackStringId] [bigint] NOT NULL,[Id] [bigint] IDENTITY(1,1) NOT NULL,[Time] [datetime] NOT NULL,CONSTRAINT [PK_Tracks] PRIMARY KEY CLUSTERED ( [Id] ASC ) WITH (PAD_INDEX = OFF,STATISTICS_NORECOMPUTE = OFF,IGNORE_DUP_KEY = OFF,ALLOW_ROW_LOCKS = ON,ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Tracks] CHECK CONSTRAINT [FK_Tracks_AudioStreams] GO ALTER TABLE [dbo].[Tracks] WITH CHECK ADD CONSTRAINT [FK_Tracks_TrackStrings] FOREIGN KEY([TrackStringId]) REFERENCES [dbo].[TrackStrings] ([Id]) GO ALTER TABLE [dbo].[Tracks] CHECK CONSTRAINT [FK_Tracks_TrackStrings] GO
和
CREATE TABLE [dbo].[TrackStrings]( [Id] [bigint] IDENTITY(1,[String] [nvarchar](512) NOT NULL,CONSTRAINT [PK_Strings] PRIMARY KEY CLUSTERED ( [Id] ASC ) WITH (PAD_INDEX = OFF,ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
我想在track表中插入一个新条目.这还将涉及在tracktrings表中插入新条目,并确保轨道中的外键列tracktringid指向tracktrings中的新条目.实现这一目标的最有效方法是什么?