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
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_USER_SEARCHES.EntityID=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DATAFORM_EXTENSION_ADDATTRIBUTE
using
VCLib.T_DATAFORM_EXTENSION ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATAFORM_EXTENSION_ADDATTRIBUTE.DataformExtension=VCLib.T_DATAFORM_EXTENSION.DataformExtensionID and VCLib.T_DATAFORM_EXTENSION.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DATAFORM_EXTENSION_ROLE
using
VCLib.T_DATAFORM_EXTENSION ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATAFORM_EXTENSION_ROLE.DataformExtension=VCLib.T_DATAFORM_EXTENSION.DataformExtensionID and VCLib.T_DATAFORM_EXTENSION.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DATAFORM_EXTENSION
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATAFORM_EXTENSION.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_ENT_ATTR_ACCESS_ENTRY
using
VCLib.T_BASE_ACCESS_ENTRY ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ENT_ATTR_ACCESS_ENTRY.EntryID=VCLib.T_BASE_ACCESS_ENTRY.EntryID and VCLib.T_BASE_ACCESS_ENTRY.type_=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_ENT_ATTR_ACCESS_ENTRY
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ENT_ATTR_ACCESS_ENTRY.EntityID=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_ENTITY_ACCESS_ENTRY
using
VCLib.T_BASE_ACCESS_ENTRY ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ENTITY_ACCESS_ENTRY.EntryID=VCLib.T_BASE_ACCESS_ENTRY.EntryID and VCLib.T_BASE_ACCESS_ENTRY.type_=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_BASE_ACCESS_ENTRY
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_BASE_ACCESS_ENTRY.type_=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_DATAFORM_TEMPLATE
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATAFORM_TEMPLATE.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_DTO_MODEL_COLUMN
using
VCLib.T_DTO_MODEL_VIEW ,
VCLib.T_DTO_MODEL ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DTO_MODEL_COLUMN.DtoModelView=VCLib.T_DTO_MODEL_VIEW.DtoModelViewID and VCLib.T_DTO_MODEL_VIEW.DtoModel=VCLib.T_DTO_MODEL.DtoModelID and VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DTO_MODEL_VIEW
using
VCLib.T_DTO_MODEL ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DTO_MODEL_VIEW.DtoModel=VCLib.T_DTO_MODEL.DtoModelID and VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DTO_ITEM
using
VCLib.T_DTO_MODEL ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DTO_ITEM.ItemDtoModel=VCLib.T_DTO_MODEL.DtoModelID and VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DTO_ITEM
using
VCLib.T_DTO_MODEL ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DTO_ITEM.DtoModel=VCLib.T_DTO_MODEL.DtoModelID and VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DTO_MODEL_FILTER
using
VCLib.T_DTO_MODEL ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DTO_MODEL_FILTER.DtoModel=VCLib.T_DTO_MODEL.DtoModelID and VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DTO_MODEL
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DTO_MODEL.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_ROLE_ATTRIBUTE_ACCESS
using
VCLib.T_HIDDEN_ATTRIBUTE ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ROLE_ATTRIBUTE_ACCESS.HiddenAttribute=VCLib.T_HIDDEN_ATTRIBUTE.HiddenAttributeID and VCLib.T_HIDDEN_ATTRIBUTE.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_HIDDEN_ATTRIBUTE
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_HIDDEN_ATTRIBUTE.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_DATA_ACCESS_ENTRY
using
VCLib.T_DATA_ACCESS ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATA_ACCESS_ENTRY.DataAccess=VCLib.T_DATA_ACCESS.DataAccessID and VCLib.T_DATA_ACCESS.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DATA_ACCESS
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATA_ACCESS.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_ENTITIES_WEB_ALIAS_ACCESS
using
VCLib.T_ENTITIES_WEB_ALIAS ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ENTITIES_WEB_ALIAS_ACCESS.EntitiesWebAlias=VCLib.T_ENTITIES_WEB_ALIAS.EntitiesWebAliasID and VCLib.T_ENTITIES_WEB_ALIAS.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_ENTITIES_WEB_ALIAS
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ENTITIES_WEB_ALIAS.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_VALIDATION_CONDITION
using
VCLib.T_DATAFORM_VALIDATION ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_VALIDATION_CONDITION.DataformValidation=VCLib.T_DATAFORM_VALIDATION.Entities and VCLib.T_DATAFORM_VALIDATION.Entities=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_DATAFORM_VALIDATION
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DATAFORM_VALIDATION.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_TEMPLATE_FIELD_VALUE
using
VCLib.T_TEMPLATE_FIELD ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_TEMPLATE_FIELD_VALUE.TemplateField=VCLib.T_TEMPLATE_FIELD.TemplateFieldID and VCLib.T_TEMPLATE_FIELD.Entity=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_TEMPLATE_FIELD
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_TEMPLATE_FIELD.Entity=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_OBJECT_COPY_TEMPLATE
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_OBJECT_COPY_TEMPLATE.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_CASCADE_DELETE_SETTING
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_CASCADE_DELETE_SETTING.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_USER_COLUMNS
using
VCLib.T_USER_CONTEXTS ,
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_USER_COLUMNS.UserContextID=VCLib.T_USER_CONTEXTS.UserContextID and VCLib.T_USER_CONTEXTS.EntityID=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_USER_CONTEXTS
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_USER_CONTEXTS.EntityID=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_DELETED_OBJECT
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_DELETED_OBJECT.Entities=VCLib.T_ENTITIES.EntityID;


delete from VCLib.T_ENTITIES_ATTRIBUTES
using
VCLib.T_ENTITIES  where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib' and VCLib.T_ENTITIES_ATTRIBUTES.EntityID=VCLib.T_ENTITIES.EntityID;

delete from VCLib.T_ENTITIES
 where  EntName = 'GEN_NUMBERS' and Schema != 'VCLib';
 
drop table ISZL.T_GEN_NUMBERS;
 