--V1.7.5Ëù×÷Éý¼¶
if exists( Select OptValue from tSysOpt where OptName='DBEdition')
begin
  Declare @DBVer varchar(10)
  Select @DBVer=OptValue from tSysOpt where OptName='DBEdition'
  Set @DBVer=Substring(@DBVer,1,4)+'-'+Substring(@DBVer,6,2)+'-'+Substring(@DBVer,9,2)
  if @DBVer>='2007-08-01'
    Return
end


if not Exists(Select * from SysColumns where Id=Object_ID('tUser') and name='DepCode' )
begin
  alter table tUser add DepCode varchar(12) null
  alter table tUser add StoreCode varchar(2) null
  Exec ('update tUser Set DepCode='''' ')
  Exec ('update tUser Set StoreCode='''' ')
  
end

if not exists(select i.name,c.Name from Sysindexes i
  inner join sysindexkeys k on i.indid=k.indid and i.id=k.id
  inner join syscolumns C on c.colid=k.colid and C.id=k.id
  where i.id=Object_ID('FJXJSB') and C.Name='FType' and i.Name like 'PK%' )
begin
	Declare @PKName varchar(60) 
    Set @PKName=''
  select @PKName=Name from SysObjects i where i.Parent_Obj=Object_ID('FJXJSB') and i.xType = 'PK'
  if Len(@PKName)>0
    Exec('ALTER TABLE [dbo].[FJXJSB] Drop CONSTRAINT '+@PKName)
  
  ALTER TABLE [dbo].[FJXJSB] Alter Column FType Char(1) not Null

  ALTER TABLE [dbo].[FJXJSB] WITH NOCHECK ADD 
	CONSTRAINT [PK_FJXJSB] PRIMARY KEY  CLUSTERED 
	(
		[FormNo],
		[ProdCode],
    [FType]
	)  ON [PRIMARY] 
end
