create table #tab_contactlist(
contact_id int identity(1,1) not null
,name varchar (100)
,address varchar (100)
,phoneno varchar (100)
,emailaddress varchar (100)
)
create table #tab_group(
group_id int identity(1,1) not null
,group_name varchar (100)
)
create table #tab_information(
contact_id int
,group_id int
)
declare @contact_id_var int
declare @group_id_var int
insert into #tab_contactlist (name,address,phoneno,emailaddress)
values ('name1','address1','phoneno1','emailaddress1')
select @contact_id_var = SCOPE_IDENTITY()
insert into #tab_group (group_name) values ('group_name1')
select @group_id_var = SCOPE_IDENTITY()
insert into #tab_information(contact_id,group_id) values (@contact_id_var ,@group_id_var)
也可以把所有的交易,以確保所有插入成功 – user3036688
先生......我已經插入值到tab_contactlist和tab_groupvalues我想提取CONTACT_ID和GROUP_ID成tab_information – shanpal
http://technet.microsoft.com/en-us/library/aa933196(v=sql.80).aspx檢查此 請選擇@contact_id_var = @@ IDENTITY !!!! – user3036688