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
|
BEGIN TRANSACTION
CREATE TABLE Tmp_userfriends
(
ownerID varchar(36) NOT NULL,
friendID varchar(36) NOT NULL,
friendPerms int NOT NULL,
datetimestamp int NOT NULL
) ON [PRIMARY]
IF EXISTS(SELECT * FROM userfriends)
EXEC('INSERT INTO dbo.Tmp_userfriends (ownerID, friendID, friendPerms, datetimestamp)
SELECT CONVERT(varchar(36), ownerID), CONVERT(varchar(36), friendID), CONVERT(int, friendPerms), CONVERT(int, datetimestamp) FROM dbo.userfriends WITH (HOLDLOCK TABLOCKX)')
DROP TABLE dbo.userfriends
EXECUTE sp_rename N'Tmp_userfriends', N'userfriends', 'OBJECT'
CREATE NONCLUSTERED INDEX IX_userfriends_ownerID ON userfriends
(
ownerID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX IX_userfriends_friendID ON userfriends
(
friendID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
COMMIT
BEGIN TRANSACTION
CREATE TABLE Tmp_userfriends
(
ownerID varchar(36) NOT NULL,
friendID varchar(36) NOT NULL,
friendPerms int NOT NULL,
datetimestamp int NOT NULL
) ON [PRIMARY]
IF EXISTS(SELECT * FROM dbo.userfriends)
EXEC('INSERT INTO dbo.Tmp_userfriends (ownerID, friendID, friendPerms, datetimestamp)
SELECT CONVERT(varchar(36), ownerID), CONVERT(varchar(36), friendID), CONVERT(int, friendPerms), CONVERT(int, datetimestamp) FROM dbo.userfriends WITH (HOLDLOCK TABLOCKX)')
DROP TABLE dbo.userfriends
EXECUTE sp_rename N'Tmp_userfriends', N'userfriends', 'OBJECT'
CREATE NONCLUSTERED INDEX IX_userfriends_ownerID ON userfriends
(
ownerID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
CREATE NONCLUSTERED INDEX IX_userfriends_friendID ON userfriends
(
friendID
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
COMMIT
|