I have some Transact-SQL that lloks like this, can it be executed through a SqlCommand object, or do I need to start learning Sql Management Objects?
BEGIN TRANSACTION
BEGIN TRY
IF NOT EXISTS
(
SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_CATALOG = (SELECT DB_NAME())
AND TABLE_NAME = 'SchemaVersion'
)
BEGIN
Print 'Migrating up...'
CREATE TABLE SchemaVersion (
Id INT IDENTITY(1,1) NOT NULL,
Version INT NOT NULL,
CONSTRAINT PK_SchemaVersion PRIMARY KEY CLUSTERED (
Id ASC
)
)
INSERT INTO SchemaVersion (Version) VALUES(1)
PRINT 'Migrated from 0 to 1'
END
ELSE IF (SELECT Version FROM SchemaVersion) = 1
BEGIN
Print 'Migrating down...'
DROP TABLE Dia_SchemaVersion
PRINT 'Migrated from 1 to 0'
END
ELSE
PRINT 'Not migrating...'
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH