日期:2014-05-17 浏览次数:20431 次
主键 点ID X Y 坐标系 转换关系
1 AAA 1 1 XXX YYY
select 点ID from tb group by 点ID
--建表
CREATE TABLE [dbo].NodTb1(
[主键] [bigint] IDENTITY(1,1) NOT NULL,
[点ID] [varchar](10) NOT NULL,
[X] bigint NOT NULL,
[Y] bigint NOT NULL,
坐标系 varchar(10),
转换关系 varchar(10)
)
--插入数据
DECLARE @max AS INT, @rc AS INT;
SET @max = 5000;
SET @rc = 1;
insert into NodTb1([点ID], [X], [Y], 坐标系, 转换关系)
select 'AAA'+cast (@rc as varchar(10)),@rc,2*@rc,'A-B'+cast (@rc as varchar(10)),'2D' +cast (@rc as varchar(10))
while @rc * 2 <= @max
begin
insert into NodTb1([点ID], [X], [Y], 坐标系, 转换关系)
select 'AAA'+cast (@rc as varchar(10)),[X] + @rc,[Y] + 2*@rc, 'A-B' +cast (@rc as varchar(10)),'2D' +cast (@rc as varchar(10)) from NodTb1
SET @rc = @rc * 2;
end
--创建索引
create index idx_A on [dbo].NodTb1(X,Y,坐标系,转换关系)
--查询示例
select [点ID] from NodTb1 where X = 4080 and Y = 8160 and 坐标系 ='A-B2048' and 转换关系 = '2D2048'
/*
点ID
----------
AAA2048
(1 行受影响)
*/
--插入新点
declare @ID varchar(10)
select top(1)@ID = [点ID] from NodTb1 where X = 4080 and Y = 8160 and 坐标系 ='A-B2048' and 转换关系 = '2D2048'
if @ID is not null
insert into NodTb([点ID], [X], [Y], 坐标系, 转换关系)
select @ID,4080,8160,'A-B2048', '2D2048'
else
insert into NodTb([点ID], [X], [Y], 坐标系, 转换关系)
select '新ID',4080,8160,'A-B2048', '2D2048'