forked from DavidWiseman/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Identity_gap_sql_server_2012.sql
68 lines (57 loc) · 1.57 KB
/
Identity_gap_sql_server_2012.sql
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
IF OBJECT_ID('t1', 'U') IS NOT NULL
DROP TABLE t1;
GO
CREATE TABLE t1 (
col1 INTEGER IDENTITY(1,1),
col2 VARCHAR(10),
col3 CHAR(10),
col4 NCHAR(10),
col5 TINYINT,
col6 BIGINT
);
GO
INSERT INTO t1 (col2, col3, col4, col5, col6)
SELECT 'val1', 'val1', 'val1', 0, 0
UNION ALL
SELECT 'val2', 'val2', 'val2', 255, 255;
SELECT *
FROM t1;
DBCC CHECKIDENT('t1', 'NORESEED');
-- Restart SQL Server
DBCC CHECKIDENT('t1', 'NORESEED');
INSERT INTO t1 (col2, col3, col4, col5, col6)
VALUES ('val3', 'val3', 'val3', 10, 10),
('val4', 'val4', 'val4', 100, 100);
SELECT *,
LEN(col1) AS integer_len,
LEN(col2) AS varchar_len,
LEN(col3) AS char_len,
LEN(col4) AS nchar_len,
LEN(col5) AS tinyint_len,
LEN(col6) AS bigint_len,
DATALENGTH(col1) AS integer_datalength,
DATALENGTH(col2) AS varchar_datalength,
DATALENGTH(col3) AS char_datalength,
DATALENGTH(col4) AS nchar_datalength,
DATALENGTH(col5) AS tinyint_datalength,
DATALENGTH(col6) AS bigint_datalength
FROM t1;
-- DBCC CHECKIDENT('t1', 'RESEED', 5);
IF EXISTS (SELECT 1 FROM sys.all_objects sao WHERE sao.name = 't1' AND sao.type = 'U')
DROP TABLE t1
ELSE PRINT 'Table t1 not exist!';
GO
BEGIN TRY
SELECT --/*
CAST(-1 AS tinyint),
1/0
--*/ * FROM t1;
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() AS ERROR_NUMBER,
ERROR_SEVERITY() AS ERROR_SEVERITY,
ERROR_STATE() AS ERROR_STATE,
ERROR_PROCEDURE() AS ERROR_PROCEDURE,
ERROR_MESSAGE() AS ERROR_MESSAGE,
ERROR_LINE() AS ERROR_LINE;
END CATCH;