SQL-Statement with dynamic table-names or redesign?

前端 未结 3 2075
慢半拍i
慢半拍i 2021-01-26 01:44

I have a MS SQL 2008 database which stores data for creating a weighted, undirected graph. The data is stored in tables with the following structure:

[id1] [int]         


        
3条回答
  •  时光取名叫无心
    2021-01-26 01:56

    SQL injection can easily be avoided in this case by comparing @tableName to the names of the existing tables. If it isn't one of them, it's bad input. (Obligatory xkcd reference: That is, unless you have a table called "bobby'; drop table students;")

    Anyway, regarding your performance problems, with partitioned tables (since SQLServer 2005), you can have the same advantages like having several tables, but without the need for dynamic SQL.

提交回复
热议问题