-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathsetup.sql
More file actions
69 lines (59 loc) · 1.82 KB
/
setup.sql
File metadata and controls
69 lines (59 loc) · 1.82 KB
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
-- go-sqlcmd Development Database Setup
-- This script runs automatically when the devcontainer starts
USE master;
GO
-- Create a test database for development
IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'SqlCmdTest')
BEGIN
CREATE DATABASE SqlCmdTest;
PRINT 'Created database: SqlCmdTest';
END
GO
-- Enable contained database authentication for testing
-- Use TRY/CATCH in case this fails on certain SQL Server configurations
BEGIN TRY
EXEC sp_configure 'contained database authentication', 1;
RECONFIGURE;
END TRY
BEGIN CATCH
PRINT 'Note: Could not enable contained database authentication (may already be enabled or not supported)';
END CATCH;
GO
-- Make SqlCmdTest a contained database for testing
BEGIN TRY
ALTER DATABASE SqlCmdTest SET CONTAINMENT = PARTIAL;
END TRY
BEGIN CATCH
PRINT 'Note: Could not set database containment (may not be supported)';
END CATCH;
GO
USE SqlCmdTest;
GO
-- Create a sample table for quick testing
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'TestTable')
BEGIN
CREATE TABLE TestTable (
ID INT IDENTITY(1,1) PRIMARY KEY,
Name NVARCHAR(100) NOT NULL,
Value NVARCHAR(MAX),
CreatedAt DATETIME2 DEFAULT GETUTCDATE()
);
INSERT INTO TestTable (Name, Value) VALUES
('Test1', 'Sample value 1'),
('Test2', 'Sample value 2'),
('Test3', 'Sample value 3');
PRINT 'Created table: TestTable with sample data';
END
GO
-- Create a view for testing
IF NOT EXISTS (SELECT * FROM sys.views WHERE name = 'TestView')
BEGIN
EXEC('CREATE VIEW TestView AS SELECT ID, Name, CreatedAt FROM TestTable');
PRINT 'Created view: TestView';
END
GO
PRINT 'go-sqlcmd development database setup complete!';
PRINT 'Test database: SqlCmdTest';
PRINT 'Sample table: TestTable (3 rows)';
PRINT 'Sample view: TestView';
GO