insert into VCLib.T_GEN_NUMBERS (GenNumbersID, EntityID, NumberName, NextNumber)
select old.GenNumbersID, old.EntityID, old.NumberName, old.NextNumber
from ISZL.T_GEN_NUMBERS old
inner join VCLib.T_ENTITIES actualEntity
on actualEntity.EntityID = old.EntityID

delete from VCLib.T_USER_SEARCHES
from VCLib.T_USER_SEARCHES
inner join VCLib.T_ENTITIES on VCLib.T_USER_SEARCHES.EntityID=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DATAFORM_EXTENSION_ADDATTRIBUTE
from VCLib.T_DATAFORM_EXTENSION_ADDATTRIBUTE
inner join VCLib.T_DATAFORM_EXTENSION on VCLib.T_DATAFORM_EXTENSION_ADDATTRIBUTE.DataformExtension=VCLib.T_DATAFORM_EXTENSION.DataformExtensionID
inner join VCLib.T_ENTITIES on VCLib.T_DATAFORM_EXTENSION.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DATAFORM_EXTENSION_ROLE
from VCLib.T_DATAFORM_EXTENSION_ROLE
inner join VCLib.T_DATAFORM_EXTENSION on VCLib.T_DATAFORM_EXTENSION_ROLE.DataformExtension=VCLib.T_DATAFORM_EXTENSION.DataformExtensionID
inner join VCLib.T_ENTITIES on VCLib.T_DATAFORM_EXTENSION.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DATAFORM_EXTENSION
from VCLib.T_DATAFORM_EXTENSION
inner join VCLib.T_ENTITIES on VCLib.T_DATAFORM_EXTENSION.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_ENT_ATTR_ACCESS_ENTRY
from VCLib.T_ENT_ATTR_ACCESS_ENTRY
inner join VCLib.T_BASE_ACCESS_ENTRY on VCLib.T_ENT_ATTR_ACCESS_ENTRY.EntryID=VCLib.T_BASE_ACCESS_ENTRY.EntryID
inner join VCLib.T_ENTITIES on VCLib.T_BASE_ACCESS_ENTRY.type_=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_ENT_ATTR_ACCESS_ENTRY
from VCLib.T_ENT_ATTR_ACCESS_ENTRY
inner join VCLib.T_ENTITIES on VCLib.T_ENT_ATTR_ACCESS_ENTRY.EntityID=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_ENTITY_ACCESS_ENTRY
from VCLib.T_ENTITY_ACCESS_ENTRY
inner join VCLib.T_BASE_ACCESS_ENTRY on VCLib.T_ENTITY_ACCESS_ENTRY.EntryID=VCLib.T_BASE_ACCESS_ENTRY.EntryID
inner join VCLib.T_ENTITIES on VCLib.T_BASE_ACCESS_ENTRY.type_=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_BASE_ACCESS_ENTRY
from VCLib.T_BASE_ACCESS_ENTRY
inner join VCLib.T_ENTITIES on VCLib.T_BASE_ACCESS_ENTRY.type_=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_DATAFORM_TEMPLATE
from VCLib.T_DATAFORM_TEMPLATE
inner join VCLib.T_ENTITIES on VCLib.T_DATAFORM_TEMPLATE.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_DTO_MODEL_COLUMN
from VCLib.T_DTO_MODEL_COLUMN
inner join VCLib.T_DTO_MODEL_VIEW on VCLib.T_DTO_MODEL_COLUMN.DtoModelView=VCLib.T_DTO_MODEL_VIEW.DtoModelViewID
inner join VCLib.T_DTO_MODEL on VCLib.T_DTO_MODEL_VIEW.DtoModel=VCLib.T_DTO_MODEL.DtoModelID
inner join VCLib.T_ENTITIES on VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DTO_MODEL_VIEW
from VCLib.T_DTO_MODEL_VIEW
inner join VCLib.T_DTO_MODEL on VCLib.T_DTO_MODEL_VIEW.DtoModel=VCLib.T_DTO_MODEL.DtoModelID
inner join VCLib.T_ENTITIES on VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DTO_ITEM
from VCLib.T_DTO_ITEM
inner join VCLib.T_DTO_MODEL on VCLib.T_DTO_ITEM.ItemDtoModel=VCLib.T_DTO_MODEL.DtoModelID
inner join VCLib.T_ENTITIES on VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DTO_ITEM
from VCLib.T_DTO_ITEM
inner join VCLib.T_DTO_MODEL on VCLib.T_DTO_ITEM.DtoModel=VCLib.T_DTO_MODEL.DtoModelID
inner join VCLib.T_ENTITIES on VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DTO_MODEL_FILTER
from VCLib.T_DTO_MODEL_FILTER
inner join VCLib.T_DTO_MODEL on VCLib.T_DTO_MODEL_FILTER.DtoModel=VCLib.T_DTO_MODEL.DtoModelID
inner join VCLib.T_ENTITIES on VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DTO_MODEL
from VCLib.T_DTO_MODEL
inner join VCLib.T_ENTITIES on VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_ROLE_ATTRIBUTE_ACCESS
from VCLib.T_ROLE_ATTRIBUTE_ACCESS
inner join VCLib.T_HIDDEN_ATTRIBUTE on VCLib.T_ROLE_ATTRIBUTE_ACCESS.HiddenAttribute=VCLib.T_HIDDEN_ATTRIBUTE.HiddenAttributeID
inner join VCLib.T_ENTITIES on VCLib.T_HIDDEN_ATTRIBUTE.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_HIDDEN_ATTRIBUTE
from VCLib.T_HIDDEN_ATTRIBUTE
inner join VCLib.T_ENTITIES on VCLib.T_HIDDEN_ATTRIBUTE.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_DATA_ACCESS_ENTRY
from VCLib.T_DATA_ACCESS_ENTRY
inner join VCLib.T_DATA_ACCESS on VCLib.T_DATA_ACCESS_ENTRY.DataAccess=VCLib.T_DATA_ACCESS.DataAccessID
inner join VCLib.T_ENTITIES on VCLib.T_DATA_ACCESS.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DATA_ACCESS
from VCLib.T_DATA_ACCESS
inner join VCLib.T_ENTITIES on VCLib.T_DATA_ACCESS.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_ENTITIES_WEB_ALIAS_ACCESS
from VCLib.T_ENTITIES_WEB_ALIAS_ACCESS
inner join VCLib.T_ENTITIES_WEB_ALIAS on VCLib.T_ENTITIES_WEB_ALIAS_ACCESS.EntitiesWebAlias=VCLib.T_ENTITIES_WEB_ALIAS.EntitiesWebAliasID
inner join VCLib.T_ENTITIES on VCLib.T_ENTITIES_WEB_ALIAS.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_ENTITIES_WEB_ALIAS
from VCLib.T_ENTITIES_WEB_ALIAS
inner join VCLib.T_ENTITIES on VCLib.T_ENTITIES_WEB_ALIAS.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_VALIDATION_CONDITION
from VCLib.T_VALIDATION_CONDITION
inner join VCLib.T_DATAFORM_VALIDATION on VCLib.T_VALIDATION_CONDITION.DataformValidation=VCLib.T_DATAFORM_VALIDATION.Entities
inner join VCLib.T_ENTITIES on VCLib.T_DATAFORM_VALIDATION.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_DATAFORM_VALIDATION
from VCLib.T_DATAFORM_VALIDATION
inner join VCLib.T_ENTITIES on VCLib.T_DATAFORM_VALIDATION.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_TEMPLATE_FIELD_VALUE
from VCLib.T_TEMPLATE_FIELD_VALUE
inner join VCLib.T_TEMPLATE_FIELD on VCLib.T_TEMPLATE_FIELD_VALUE.TemplateField=VCLib.T_TEMPLATE_FIELD.TemplateFieldID
inner join VCLib.T_ENTITIES on VCLib.T_TEMPLATE_FIELD.Entity=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_TEMPLATE_FIELD
from VCLib.T_TEMPLATE_FIELD
inner join VCLib.T_ENTITIES on VCLib.T_TEMPLATE_FIELD.Entity=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_OBJECT_COPY_TEMPLATE
from VCLib.T_OBJECT_COPY_TEMPLATE
inner join VCLib.T_ENTITIES on VCLib.T_OBJECT_COPY_TEMPLATE.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_CASCADE_DELETE_SETTING
from VCLib.T_CASCADE_DELETE_SETTING
inner join VCLib.T_ENTITIES on VCLib.T_CASCADE_DELETE_SETTING.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_USER_COLUMNS
from VCLib.T_USER_COLUMNS
inner join VCLib.T_USER_CONTEXTS on VCLib.T_USER_COLUMNS.UserContextID=VCLib.T_USER_CONTEXTS.UserContextID
inner join VCLib.T_ENTITIES on VCLib.T_USER_CONTEXTS.EntityID=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_USER_CONTEXTS
from VCLib.T_USER_CONTEXTS
inner join VCLib.T_ENTITIES on VCLib.T_USER_CONTEXTS.EntityID=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_DELETED_OBJECT
from VCLib.T_DELETED_OBJECT
inner join VCLib.T_ENTITIES on VCLib.T_DELETED_OBJECT.Entities=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';


delete from VCLib.T_ENTITIES_ATTRIBUTES
from VCLib.T_ENTITIES_ATTRIBUTES
inner join VCLib.T_ENTITIES on VCLib.T_ENTITIES_ATTRIBUTES.EntityID=VCLib.T_ENTITIES.EntityID
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

delete from VCLib.T_ENTITIES
 where  EntName = 'GEN_NUMBERS' and [Schema] != 'VCLib';

drop table ISZL.T_GEN_NUMBERS;
