开发者

primary key in linked csv using schema.ini somehow?

开发者 https://www.devze.com 2023-01-20 12:00 出处:网络
For a number of reasons I have to use a linked csv file in a sqlexpress database. Col1 is always u开发者_运维百科nique, although the data changes periodically, based on current logins.

For a number of reasons I have to use a linked csv file in a sqlexpress database. Col1 is always u开发者_运维百科nique, although the data changes periodically, based on current logins.

Is there a way to set as a primary key in some manner using the schema.ini or some other way?


You can't have a primary key or any other index defined in schema.ini.

You also can't have a view that boldly selects all data from the linked server and defines a unique index on it, because the view must be with schemabinding to enable indices, and that's not allowed for cross-database objects.

The only possible solution seems to be creating a user-defined function that selects all data into a table with a primary key:

create function dbo.csv_primary()
returns @result table (col1 int not null primary key, col2 varchar(255))
as
begin
  insert into @result(col1, col2)
  select col1, col2 from CSVServer.[folder]..[file#csv];

  return;
end;

A multi-step table-valued function will obviously kill performance, but then, how much performance do you get when querying a csv file.

0

精彩评论

暂无评论...
验证码 换一张
取 消