summaryrefslogtreecommitdiff
path: root/www/wiki/maintenance/mssql/archives/patch-site_stats-modify.sql
blob: b2de94833c281a985e478539da200752e69a8edc (plain)
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
/* Delete old default constraints */
DECLARE @sql nvarchar(max)
SET @sql=''

/* IMHO: A DBMS where you have to do THIS to change a default value sucks. */
SELECT @sql= @sql + 'ALTER TABLE site_stats DROP CONSTRAINT ' + df.name + '; '
FROM sys.default_constraints df
JOIN sys.columns c
	ON c.object_id = df.parent_object_id
	AND c.column_id = df.parent_column_id
WHERE
	df.parent_object_id =  OBJECT_ID('site_stats');--

EXEC sp_executesql @sql;

/* Change data type of ss_images from int to bigint.
 * All other fields (except ss_row_id) already are bigint.
 * This MUST happen before adding new constraints. */
ALTER TABLE site_stats ALTER COLUMN ss_images bigint;

/* Add new default constraints.
 * Don't ask me why I have to repeat ALTER TABLE site_stats
 * instead of using commas, for some reason SQL Server 2016
 * didn't accept it in any other way. Maybe I just don't know
 * enough about mssql, but this works.
 */
ALTER TABLE site_stats ADD CONSTRAINT col_ss_total_edits DEFAULT NULL FOR ss_total_edits;
ALTER TABLE site_stats ADD CONSTRAINT col_ss_good_article DEFAULT NULL FOR ss_good_articles;
ALTER TABLE site_stats ADD CONSTRAINT col_ss_total_pages DEFAULT NULL FOR ss_total_pages;
ALTER TABLE site_stats ADD CONSTRAINT col_ss_users DEFAULT NULL FOR ss_users;
ALTER TABLE site_stats ADD CONSTRAINT col_ss_active_users DEFAULT NULL FOR ss_active_users;
ALTER TABLE site_stats ADD CONSTRAINT col_ss_images DEFAULT NULL FOR ss_images;