--系统启动是先建表再执行sql文件的升级 
IF OBJECT_ID('FixedBarcode', 'U') is null
BEGIN  
	--所以一般情况下是不会进这里的。
	SELECT ti.id,td.id as ancestorID  
	into FixedBarcode
	from TousseInstance ti 
	join TousseDefinition td on td.id=ti.tousseDefinition_id
	where ti.tousseFixedBarcode=1 and td.forDisplay=1  
END 
else if not EXISTS (SELECT 1 FROM FixedBarcode) 
BEGIN  
    INSERT INTO FixedBarcode (id, ancestorID)  
    SELECT   
        ti.id,  
        td.id as ancestorID  
    FROM   
        TousseInstance ti  
    JOIN   
    TousseDefinition td ON ti.tousseDefinition_id = td.id
	where ti.tousseFixedBarcode=1 and td.forDisplay=1
END;