/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MDS_table.sql **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_PRODUCTFAMILY')
 CREATE TABLE T_MDS_PRODUCTFAMILY (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER NVARCHAR(30) DEFAULT ' ' NOT NULL,
FSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FMATERIELITEM BIGINT DEFAULT 0 NOT NULL,
FMATERIELPBOM BIGINT DEFAULT 0 NOT NULL,
FPRODUCTFAMILY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPBOMNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBOMTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FITEMSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSUPMODEL NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPLANUSER BIGINT DEFAULT 0 NOT NULL,
FPLANUSERCODE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FGENERALTAG NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOFFERINGSHOW NVARCHAR(255) DEFAULT ' ' NOT NULL,
FPBOMNAMESHOW NVARCHAR(255) DEFAULT ' ' NOT NULL,
FITEMNAMESHOW NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MDS_PRODUCTFAMILY_L')
 CREATE TABLE T_MDS_PRODUCTFAMILY_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME VARCHAR(100) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_MDS_PRODUCTFAMILY', 'T_MDS_PRODUCTFAMILY', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MDS_PRODUCTFAMILY') CREATE INDEX IDX_MDS_PRODUCTFAMILY ON T_MDS_PRODUCTFAMILY ( FMATERIELITEM );


 EXEC P_ALTERPK 'PK_T_MDS_PRODUCTFAMILY_L', 'T_MDS_PRODUCTFAMILY_L', 'FPKID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_MDS_PRODUCTFAMILY_L') CREATE INDEX IDX_MDS_PRODUCTFAMILY_L ON T_MDS_PRODUCTFAMILY_L ( FID ,FLOCALEID );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_PRODUCTFAMILY' AND KSQL_COL_NAME ='FOFFERINGSHOW')
 ALTER TABLE T_MDS_PRODUCTFAMILY ADD (FOFFERINGSHOW NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_PRODUCTFAMILY' AND KSQL_COL_NAME ='FPBOMNAMESHOW')
 ALTER TABLE T_MDS_PRODUCTFAMILY ADD (FPBOMNAMESHOW NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_PRODUCTFAMILY' AND KSQL_COL_NAME ='FITEMNAMESHOW')
 ALTER TABLE T_MDS_PRODUCTFAMILY ADD (FITEMNAMESHOW NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_PRODUCTFAMILY' AND KSQL_COL_NAME ='FCREATEORGID')
 ALTER TABLE T_MDS_PRODUCTFAMILY ADD (FCREATEORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_PRODUCTFAMILY' AND KSQL_COL_NAME ='FORGID')
 ALTER TABLE T_MDS_PRODUCTFAMILY ADD (FORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MDS_PRODUCTFAMILY' AND KSQL_COL_NAME ='FCTRLSTRATEGY')
 ALTER TABLE T_MDS_PRODUCTFAMILY ADD (FCTRLSTRATEGY NVARCHAR(50) DEFAULT ' ' NOT NULL );



/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MDS_table.sql **/
