--Remove the ION user with DBO role membership and 
--assign it as the DBO. Needed to make NON-SAFE CLR
--content continue to run after DB attach/detach
--
--NOTE: we know in ION Enterprise that no database objects
--are ever associated with a schema so the DROP will succeed

--Remove the ION schema
IF EXISTS (SELECT * FROM sys.schemas WHERE name = 'ION')
BEGIN
	DROP SCHEMA ION
END

--Remove the ION user
IF EXISTS (SELECT * FROM dbo.sysusers WHERE name = 'ION')
BEGIN
	DROP USER ION
END

--Assign the ION login as DBO
IF EXISTS (SELECT * FROM master.dbo.syslogins WHERE loginname = N'ION')
BEGIN
	EXEC sp_changedbowner 'ION'
END
GO