Print ''
Print '-------------------------------------------------------------------------'
Print ' using Database: #DB_N#'
Print ' Table         : [SolidEdge_AssebmlyReferences_tbl]'
Print ' Creation Date : 07.11.2019'
Print ' Autor         : S.Gueth'
Print ' '
Print '-------------------------------------------------------------------------'

use [#DB_N#]

Declare @MyActionMsg1 nvarchar (max)
Declare @MyTableName nvarchar (max)
    set @MyTableName='SolidEdge_AssebmlyReferences_tbl'

--------------------------------------------------------------------------------
-- verzweigen auf TableCreate: oder TableUpdate:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SolidEdge_AssebmlyReferences_tbl]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  BEGIN
   goto TableUpdate
  END
ELSE
  BEGIN
   goto TableCreate
  END
  


--------------------------------------------------------------------------------
TableCreate:
  set @MyActionMsg1=
      '-- Table: [SolidEdge_AssebmlyReferences_tbl] dose not exist and will be created new'
  Print (@MyActionMsg1)

  CREATE TABLE [dbo].[SolidEdge_AssebmlyReferences_tbl] (
  
          [ID]                     [uniqueidentifier] NOT NULL DEFAULT newid(),
          [ParentJMObjectTbl_ID]   [uniqueidentifier] NOT NULL,
          [ChildJMObjectTbl_ID]    [uniqueidentifier] ,
          [ParentFile_DPNE]        [nvarchar]  (256) ,
          [ChildFile_DPNE]         [nvarchar]  (256) ,
          [ChildFileOriginal_DPNE] [nvarchar]  (256) ,
          [NatureLink]             [nvarchar]  (10) NOT NULL

  ) ON [PRIMARY]

  goto CheckCreateIndex


--------------------------------------------------------------------------------
TableUpdate:

  set @MyActionMsg1=
       '-- Table: [SolidEdge_AssebmlyReferences_tbl] exist and will be updated'
  Print (@MyActionMsg1)

  Declare @ColumeName nvarchar (256)
  Declare @ColumeNameOld nvarchar (256)
  Declare @ColumeNameNew nvarchar (256)
  Declare @ExecuteSQLstr nvarchar (max)


--   set @ColumeName='ComputerFQDN'
--   if (Select Coalesce(Col_length(@MyTableName,@ColumeName),0)) = 0
--     begin
--       print ('Create Column:' + @ColumeName + ' [(new 09.07.2010)]')
--       set @ExecuteSQLstr='ALTER TABLE [dbo].[' + @MyTableName + '] ADD [' + @ColumeName +'] [nvarchar] (256) NULL'
--       execute (@ExecuteSQLstr)
--     end



goto CheckCreateIndex
--------------------------------------------------------------------------------
  CheckCreateIndex:

   EXECUTE JF_PrimKeyCheckCreateDef 'ID_pk',   @MyTableName, 'ID'
  
--------------------------------------------------------------------------------
EndeExit:
 Print '------------------------------------------------------------------------'
 Print 'Done on Database: #DB_N#'
 Print '------------------------------------------------------------------------'

GO
