Sql 也是主键@gbn:因为我的文件名为“type”,长度为500。我是否应该将其设为主键?对于索引,500可能太大,可能创建另一个列来保存类型列的散列值,索引为?@Magnus-max bytes per index key=900,它是varchar,而不是
Sql 也是主键@gbn:因为我的文件名为“type”,长度为500。我是否应该将其设为主键?对于索引,500可能太大,可能创建另一个列来保存类型列的散列值,索引为?@Magnus-max bytes per index key=900,它是varchar,而不是,sql,sql-server-2005,stored-procedures,query-optimization,Sql,Sql Server 2005,Stored Procedures,Query Optimization,也是主键@gbn:因为我的文件名为“type”,长度为500。我是否应该将其设为主键?对于索引,500可能太大,可能创建另一个列来保存类型列的散列值,索引为?@Magnus-max bytes per index key=900,它是varchar,而不是nvarchar,所以应该没问题。@Damien_,不信者,如果有那么大的聚集索引,碎片不是很大吗?@Magnus-我不建议将其用于聚集索引,不。@gbn:因为我的名为“type”的字段长度为500。我是否应该将其设为主键?对于索引,500可能
也是主键@gbn:因为我的文件名为“type”,长度为500。我是否应该将其设为主键?对于索引,500可能太大,可能创建另一个列来保存类型列的散列值,索引为?@Magnus-max bytes per index key=900,它是varchar,而不是nvarchar,所以应该没问题。@Damien_,不信者,如果有那么大的聚集索引,碎片不是很大吗?@Magnus-我不建议将其用于聚集索引,不。@gbn:因为我的名为“type”的字段长度为500。我是否应该将其设为主键?对于索引,500可能太大,可能创建另一个列来保存类型列的散列值,索引为?@Magnus-max bytes per index key=900,它是varchar,而不是nvarchar,所以这应该没问题。@Damien_不信者,如果有那么大的聚集索引,碎片不是很大吗?@Magnus-我不建议将其用于聚集索引,不。这也与我在评论中提到的竞争类似-当类型不存在时,可以执行两次更新,然后两者都尝试插入。这也遭遇了类似于我在评论中提到的竞争——当类型不存在时,两次执行可以运行更新,然后两者都尝试插入。
CREATE TABLE [dbo].[tblurlcounter](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[type] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[count] [bigint] NULL,
CONSTRAINT [PK_tblurlcounter] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
declare @count int
select @count= [count] from tblurlcounter where [type] = @type
if @count > 0
begin
update tblurlcounter set [count]=@count + 1 where [type] = @type
select @count + 1
end
else
begin
INSERT INTO [dbcounter].[dbo].[tblurlcounter]
([type]
,[count])
VALUES
(@type
,1)
end
update tblurlcounter set [count] = [count] + 1 where [type] = @type
if @@rowcount = 0
begin
insert into tblurlcounter
([type],[count])
values
(@type, 1)
end
select @count = [count] from tblurlcounter where [type] = @type
INSERT INTO [dbcounter].[dbo].[tblurlcounter]
([type]
,[count])
VALUES
(@type
,0)
WHERE NOT EXISTS(select 1 from tblurlcounter where [type] = @type)
UPDATE tblurlcounter SET [count]=[count] + 1 where [type] = @type