In SQL Server 2008, consider the table
create table myTable (id int, filler char(X)) with (data_compression = Y)
where X is an integer of varying size, and Y is either “row”, “page” or “none”. In an experiment, I would like to specify X and Y programatically in T-SQL, so that I can measure a number of performance metrics for a large (!) amount of different (X,Y) pairs.
However, the following is not allowed:
declare @mySize int = 100
create table myTable (id int, filler char(@mySize)) ...
How can I then specify the char width and compression type programatically?
You could use dynamic SQL, for example: