1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
| CREATE TABLE lob_storage_direct
(
lsd_id int NOT NULL IDENTITY
CONSTRAINT PK_lob_storage_direct PRIMARY KEY
, lsd_name varchar(16) NOT NULL
CONSTRAINT UQ_lob_storage_direct__lsd_name UNIQUE
, lsd_value varchar(max) NOT NULL
CONSTRAINT CHK_lob_storage_direct__lsd_value CHECK (LEN(lsd_value) > 0)
)
-- Peuplement de la table avec quelques lignes ...
;WITH
CTE AS
(
SELECT SUBSTRING
(
REPLACE(CAST(NEWID() AS varchar(36)), '-', '')
, ABS(CHECKSUM(NEWID())) % 8
, 8 + ABS(CHECKSUM(NEWID())) % 8
) AS lsd_name
, REPLICATE
(
SUBSTRING
(
REPLACE(CAST(NEWID() AS varchar(36)), '-', '')
, (ABS(CHECKSUM(NEWID())) % 8) + 1
, 9 + (ABS(CHECKSUM(NEWID())) % 8)
)
, ABS(CHECKSUM(NEWID())) % 100
) AS lsd_value
FROM sys.objects AS A
CROSS JOIN sys.objects AS B
)
INSERT INTO dbo.lob_storage_direct
(
lsd_name
, lsd_value
)
SELECT lsd_name
, lsd_value
FROM CTE
WHERE LEN(lsd_value) > 0
GO
-- Métadonnées d'allocation de l'espace pour cette table
SELECT OBJECT_SCHEMA_NAME(P.object_id) table_schema
, OBJECT_NAME(P.object_id) table_name
, P.index_id
, P.partition_number
, AU.allocation_unit_id
, AU.type_desc
, AU.total_pages
, AU.used_pages
, AU.data_pages
FROM sys.partitions AS P
INNER JOIN sys.system_internals_allocation_units AS AU
ON AU.container_id = P.partition_id
WHERE P.object_id = OBJECT_ID('dbo.lob_storage_direct')
ORDER BY table_schema, table_name, P.index_id, P.partition_number, AU.type;
GO
-- Création d'une nouvelle table à la structure identique
CREATE TABLE dbo.lob_storage_out_of_row
(
lsd_id int NOT NULL IDENTITY
CONSTRAINT PK_lob_storage_out_of_row PRIMARY KEY
, lsd_name varchar(16) NOT NULL
CONSTRAINT UQ_lob_storage_out_of_row__lsoor_name UNIQUE
, lsd_value varchar(max) NOT NULL
CONSTRAINT CHK_lob_storage_out_of_row__lsoor_value CHECK (LEN(lsd_value) > 0)
)
GO
-- Forçage du stockage des LOB dans des pages de type LOB_DATA
EXEC sp_tableoption
'dbo.lob_storage_out_of_row'
, 'large value types out of row'
, 1
GO
-- Echange des structures
-- Ceci est instantané puisque c'est un simple échange de métadonnées sur les numéros d'unité d'allocation
ALTER TABLE dbo.lob_storage_direct
SWITCH TO dbo.lob_storage_out_of_row
GO
-- Métadonnées d'allocation de l'espace pour la nouvelle table
SELECT OBJECT_SCHEMA_NAME(P.object_id) table_schema
, OBJECT_NAME(P.object_id) table_name
, P.index_id
, P.partition_number
, AU.allocation_unit_id
, AU.type_desc
, AU.total_pages
, AU.used_pages
, AU.data_pages
FROM sys.partitions AS P
INNER JOIN sys.system_internals_allocation_units AS AU
ON AU.container_id = P.partition_id
WHERE P.object_id = OBJECT_ID('dbo.lob_storage_out_of_row')
ORDER BY table_schema, table_name, P.index_id, P.partition_number, AU.type; |
Partager