0
我有兩個表:如何插入標識值到另一個表
create table Clients
(
id_client int not null identity(1,1) Primary Key,
name_client varchar(10) not null,
phone_client int not null
)
create table Sales
(
id_sale int not null identity(1,1) Primary Key,
date_sale date not null,
total_sale float not null
id_clients int not null identity(1,1) Foreign Key references Clients
)
所以,讓我們插入到客戶端(「拉爾夫」,00000000),該id_client將是1(明顯)。問題是:我如何將1插入銷售?
我沒有注意到我在表Sales中留下了id_clients作爲Identity,感謝您的意見。解決方案非常簡單: 插入銷售值(......,(從客戶端選擇id_clients))。 非常感謝,我的朋友。你搖滾:D – RalphVB
對不起,我解決這個問題的正確方法是用IDENT_CURRENT:D – RalphVB
@RalphVB:我建議你使用'SCOPE_IDENTITY'而不是'IDENT_CURRENT' –