-- 以省市表为例,主键自增 

CREATE TABLE [nis_provinces] (

[id] [int] IDENTITY (1, 1) NOT NULL ,
[provinces] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[fatherid] [int] NOT NULL ,
CONSTRAINT [PK_nis_provinces] PRIMARY KEY  CLUSTERED 
(
[id]
)  ON [PRIMARY] 
) ON [PRIMARY]
GO 

 insert into nis_provinces values('北京市',0);

想插入北京各区数据,在oracle中,可以这样写:

insert into  nis_provinces values('东城区',select id from nis_provinces where provinces='北京市') ;

但在sql server的insert语句中,不能使用子查询,要写成这样: 

insert into nis_provinces select '东城区',id from nis_provinces where provinces='北京市';
insert into nis_provinces select '西城区',id from nis_provinces where provinces='北京市';

相关文章:

  • 2021-11-05
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
猜你喜欢
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2021-08-08
相关资源
相似解决方案