/*

   2003年7月3日 17:19:11

   用户: 

   服务器: SRV2003

   数据库: Sapp_metal

   应用程序: SQL Server Enterprise Manager

*/



BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
COMMIT
BEGIN TRANSACTION
CREATE TABLE dbo.Reportmoddw
	(
 	winname char(50) NOT NULL,
	dwname char(30) NOT NULL
	) ON [PRIMARY]
GO
ALTER TABLE dbo.Reportmoddw ADD CONSTRAINT
	PK_Reportmoddw PRIMARY KEY NONCLUSTERED 
	(
	winname,
	dwname
	) ON [PRIMARY]
GO
COMMIT

if exists (select * from sysobjects where id = object_id(N'[dbo].[t_reportdw_update]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_reportdw_update]
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[t_reportdw_delete]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_reportdw_delete]
GO

SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO


CREATE TRIGGER t_reportdw_update ON [Reportdw] 
FOR UPDATE
AS


DECLARE @volddwname char(30)
DECLARE @vnewdwname char(30)

IF UPDATE(dwname)
BEGIN
 SELECT @volddwname = (SELECT dwname FROM deleted)
 SELECT @vnewdwname = (SELECT dwname FROM inserted)

 UPDATE reportwindw SET dwname = @vnewdwname WHERE dwname = @volddwname

 UPDATE reporttabledw SET dwname = @vnewdwname WHERE dwname = @volddwname

 UPDATE reportdefine SET dwname = @vnewdwname WHERE dwname = @volddwname

 UPDATE reportmoddw SET dwname = @vnewdwname WHERE dwname = @volddwname


END




GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO


CREATE TRIGGER t_reportdw_delete ON [Reportdw] 
FOR DELETE 
AS

 DELETE FROM reportwindw WHERE dwname in (SELECT dwname FROM deleted)

 DELETE FROM reporttabledw WHERE dwname in (SELECT dwname FROM deleted)

 DELETE FROM reportdefine WHERE dwname in (SELECT dwname FROM deleted)

 DELETE FROM reportmoddw WHERE dwname in (SELECT dwname FROM deleted)


GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[t_reportmod_delete]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_reportmod_delete]
GO

SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO


CREATE TRIGGER t_reportmod_delete ON [reportmod] 
FOR DELETE 
AS

 
 DELETE FROM reportmodwin WHERE winname in (SELECT winname FROM deleted)

 DELETE FROM reportmoddw WHERE winname in (SELECT winname FROM deleted)


GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[t_reportmodwin_triggers]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_reportmodwin_triggers]
GO

SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

CREATE TRIGGER t_reportmodwin_triggers ON [reportmodwin] 
FOR INSERT, UPDATE
AS

DECLARE @vtable char(10)
DECLARE @vcount int

  DECLARE cursor_moddw SCROLL CURSOR 
     FOR SELECT tablename
	FROM inserted
   OPEN cursor_moddw
   FETCH NEXT FROM cursor_moddw INTO @vtable
   WHILE (@@fetch_status <> -1)
     BEGIN 
       IF (@@fetch_status <> -2) 
       BEGIN
	 SELECT @vcount = (SELECT COUNT(*) FROM reporttabledw WHERE tablename = @vtable)

	 IF @vcount = 0 
	 BEGIN
	    INSERT INTO reporttabledw (tablename , dwname) 
			(SELECT DISTINCT tablename ,  dwname 
				FROM inserted , reportmoddw
				WHERE inserted.winname = reportmoddw.winname AND 
					inserted.tablename = @vtable)
	 END	
       END
       FETCH NEXT FROM cursor_moddw INTO @vtable
     END 
   CLOSE cursor_moddw
   DEALLOCATE cursor_moddw

GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO


if exists (select * from sysobjects where id = object_id(N'[dbo].[t_reportmodwin_delete]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_reportmodwin_delete]
GO


SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

CREATE TRIGGER t_reportmodwin_delete ON [reportmodwin] 
FOR DELETE 
AS

  DELETE FROM reporttabledw WHERE tablename in (SELECT tablename FROM deleted)

  DELETE FROM reportdefine WHERE tablename in (SELECT tablename FROM deleted)
GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[t_reports_delete]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_reports_delete]
GO


SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

CREATE TRIGGER t_reports_delete ON [reports] 
FOR DELETE 
AS

  DELETE FROM reportmodwin WHERE tablename in (SELECT tablename FROM deleted)

  DELETE FROM reporttabledw WHERE tablename in (SELECT tablename FROM deleted)

  DELETE FROM reportdefine WHERE tablename in (SELECT tablename FROM deleted)

GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

ALTER TABLE [dbo].[yk_sfmx] DROP CONSTRAINT f_flag_dw_fph
GO


if exists (select * from sysobjects where id = object_id(N'[dbo].[t_yk_rkdmx_update]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[t_yk_rkdmx_update]
GO


SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

/****** Object:  Trigger dbo.t_yk_rkdmx_update    Script Date: 00-9-20 18:19:37 ******/
/****** Object:  Trigger dbo.t_yk_rkdmx_update    Script Date: 00-9-20 16:45:47 ******/
/****** Object:  Trigger dbo.t_yk_rkdmx_update    Script Date: 99-11-7 22:24:54 ******/
CREATE TRIGGER t_yk_rkdmx_update ON dbo.yk_rkdmx 
FOR UPDATE
AS
 DECLARE @vdh int
 DECLARE @vnum int
 DECLARE @vfph char(15)
 DECLARE @vje numeric(10,2)
 DECLARE @vfkrq smalldatetime
 DECLARE @vdwbm char(8)
 DECLARE @vje0 numeric(10,2)
 DECLARE @vyfje numeric(10,2)
 DECLARE @vje1 numeric(10,2)
 DECLARE @vrowcount int
 DECLARE @vlb char(2)
 DECLARE @vthsl0 numeric(10,2)
 DECLARE @vthsl numeric(10,2)
 DECLARE @vsl numeric(10,2)
 DECLARE @vjj numeric(10,4)
 DECLARE @vpfj numeric(10,4)
 DECLARE @vypbm char(20)
 DECLARE @vbzgg char(10)
 DECLARE @vysje numeric(12,2)
 

/******************************************************************************************
  处理填发票号
******************************************************************************************/
 IF UPDATE(rmx_fph)
 BEGIN
  DECLARE avg_cursor SCROLL CURSOR 
     FOR SELECT rmx_fph,rmx_je,rmx_dh,rmx_thsl,rmx_sl,
		rmx_jj FROM inserted WHERE rmx_flag = 1
   OPEN avg_cursor
   FETCH NEXT FROM avg_cursor INTO @vfph,@vje,@vdh,@vthsl,@vsl,@vjj
   WHILE (@@fetch_status <> -1)
     BEGIN 
       IF (@@fetch_status <> -2) 
       BEGIN
	  IF @vfph IS NOT NULL
          BEGIN
	    SELECT @vje = @vjj * (@vsl - @vthsl)

	    SELECT @vdwbm = ( SELECT rkd_hy FROM yk_rkd WHERE rkd_num=@vdh GROUP BY rkd_hy)
	    SELECT @vfkrq = ( SELECT rkd_fkrq FROM yk_rkd WHERE rkd_num=@vdh GROUP BY rkd_fkrq)
	    SELECT @vrowcount = (SELECT COUNT(*) FROM yk_sfkz 
                       WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1')
	    IF @vrowcount > 0
	        UPDATE yk_sfkz SET sf_je = sf_je + @vje 
			WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1'
	    ELSE
	        INSERT yk_sfkz(sf_fph,sf_dwbm,sf_je,sf_flag,sf_rq0)
	               VALUES(@vfph,@vdwbm,@vje,'1',@vfkrq)

	   UPDATE yk_sfkz SET sf_je = sf_je - @vje 
			WHERE sf_dwbm=@vdwbm AND sf_fph='无发票' AND sf_flag='1'

	   DELETE FROM yk_sfmx
		WHERE sfmx_dwbm=@vdwbm AND sfmx_fph='无发票' AND sfmx_flag='1' AND sfmx_je<=0
                  
	   DELETE yk_sfkz
		WHERE sf_dwbm=@vdwbm AND sf_fph='无发票' AND sf_flag='1' AND sf_je<=0
          END  
	  
       END
       FETCH NEXT FROM avg_cursor INTO @vfph,@vje,@vdh,@vthsl,@vsl,@vjj
     END 
   CLOSE avg_cursor
   DEALLOCATE avg_cursor
 END
/******************************************************************************************
  处理冲减入库记录
******************************************************************************************/
 IF UPDATE(rmx_cjry) 
 BEGIN
  BEGIN TRANsaction
  DELETE yk_zz WHERE zz_num = (SELECT inserted.rmx_num FROM inserted )
  DECLARE cj_cursor SCROLL CURSOR 
     FOR SELECT rmx_fph,rmx_je,rmx_dh,rmx_num , rmx_sl , rmx_thsl , rmx_jj FROM inserted
	WHERE rmx_flag = 1
   OPEN cj_cursor
   FETCH NEXT FROM cj_cursor INTO @vfph,@vje,@vdh ,@vnum,@vsl,@vthsl,@vjj
   WHILE (@@fetch_status <> -1)
     BEGIN 
       IF (@@fetch_status <> -2) 
       BEGIN

          SELECT @vdwbm = ( SELECT rkd_hy FROM yk_rkd WHERE rkd_num=@vdh GROUP BY rkd_hy)
          SELECT @vthsl0 = ( SELECT rmx_thsl FROM deleted WHERE rmx_num=@vnum)
          SELECT @vje0 = @vjj * (@vsl - @vthsl0)
      
          SELECT @vje0 = ( SELECT CONVERT(numeric(10,2),rmx_jj * (rmx_sl - rmx_thsl)) 
				FROM deleted WHERE rmx_num=@vnum)
          SELECT @vlb = ( SELECT rkd_lb FROM yk_rkd WHERE rkd_num=@vdh)
	  IF @vlb='RK'
          BEGIN
	    IF @vfph IS NOT NULL
	      BEGIN
	          SELECT @vyfje = ( SELECT sf_yfje FROM yk_sfkz 
			WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1')
	          SELECT @vje1 = ( SELECT sf_je FROM yk_sfkz 
			WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1')
          
	 	  IF @vje0 <= @vje1 - @vyfje
		     UPDATE yk_sfkz SET sf_je = sf_je - @vje0 + @vje 
			WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1'
	          ELSE
                    BEGIN
		        RAISERROR ('本次要冲减部分已付款，不能再冲减!',16,-1)
			ROLLBACK TRANsaction
			RETURN
   END
	      END	
	    ELSE
	      BEGIN
	          SELECT @vyfje = ( SELECT sf_yfje FROM yk_sfkz 
			WHERE sf_dwbm=@vdwbm AND sf_fph='无发票' AND sf_flag='1')
	          SELECT @vje1 = ( SELECT sf_je FROM yk_sfkz 
			WHERE sf_dwbm=@vdwbm AND sf_fph='无发票' AND sf_flag='1')
          
	 	  IF @vje0 <= @vje1 - @vyfje
		     UPDATE yk_sfkz SET sf_je = sf_je - @vje0 + @vje 
			WHERE sf_dwbm=@vdwbm AND sf_fph='无发票' AND sf_flag='1'
	          ELSE
                    BEGIN
		        RAISERROR ('本次要冲减部分已付款，不能再冲减!',16,-1)
			ROLLBACK TRANsaction
			RETURN
                    END
	      END	
          END 
       END
       FETCH NEXT FROM cj_cursor INTO @vfph,@vje,@vdh,@vnum,@vsl,@vthsl,@vjj
     END 
   CLOSE cj_cursor
   DEALLOCATE cj_cursor
   DELETE yk_sfkz WHERE sf_je <= 0
   DELETE yk_mxz WHERE mx_crnum = (SELECT rmx_num FROM inserted) AND mx_lb = 1
   DELETE yk_ty WHERE ty_zznum = (SELECT rmx_num FROM inserted) 
   COMMIT TRANsaction 
 END

 IF UPDATE(rmx_thsl)
 BEGIN
  DECLARE th_cursor SCROLL CURSOR 
     FOR SELECT rkd_hy , rmx_num , rmx_thsl , rmx_jj , rmx_sl , rmx_fph
	FROM inserted , yk_rkd WHERE rmx_dh = rkd_num AND rmx_flag = 1
   OPEN th_cursor
   FETCH NEXT FROM th_cursor INTO @vdwbm , @vnum , @vthsl , @vjj , @vsl , @vfph
   WHILE (@@fetch_status <> -1)
     BEGIN 
       IF (@@fetch_status <> -2) 
       BEGIN
         SELECT @vthsl0 = (SELECT rmx_thsl FROM deleted WHERE rmx_num = @vnum)	

         IF @vthsl0 > 0
         BEGIN
	    SELECT @vje = @vjj * (@vthsl - @vthsl0)
            UPDATE yk_zz SET zz_sl = zz_sl - (@vthsl - @vthsl0) WHERE zz_num = @vnum
         END
         ELSE
         BEGIN
	    SELECT @vje = @vjj * @vthsl
            UPDATE yk_zz SET zz_sl = zz_sl - @vthsl WHERE zz_num = @vnum
         END

        IF @vfph IS NOT NULL
          UPDATE yk_sfkz SET sf_je = sf_je - @vje 
		WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1'
        ELSE
	  UPDATE yk_sfkz SET sf_je = sf_je - @vje 
		WHERE sf_dwbm=@vdwbm AND sf_fph='无发票' AND sf_flag='1'
	  
       END
       FETCH NEXT FROM th_cursor INTO  @vdwbm , @vnum , @vthsl , @vjj , @vsl , @vfph
     END 
   CLOSE th_cursor
   DEALLOCATE th_cursor
 END

 IF UPDATE(rmx_flag)
 BEGIN
/*
   INSERT INTO yk_zz  SELECT B.rmx_num,B.rmx_ypbm,B.rmx_bzgg,B.rmx_dw,B.rmx_jj,B.rmx_pfj,
	               	    B.rmx_lsj,B.rmx_sl,B.rmx_ph,B.rmx_rxrq,B.rmx_hw,B.rmx_cj,A.rkd_rq,
                            B.rmx_otcj , B.rmx_xydj , A.rkd_ckdh , B.rmx_scrq
		            FROM yk_rkd A,inserted B
		            WHERE B.rmx_dh=A.rkd_num
*/

   INSERT INTO yk_zz (zz_num , zz_ypbm ,zz_bzgg , zz_dw , zz_jj , zz_pfj , 
			zz_lsj , zz_sl , zz_ph , zz_rxrq , zz_hw , zz_cj , zz_rkrq , 
			zz_otcj , zz_xydj , zz_ckdh , zz_scrq) 
			 SELECT B.rmx_num,B.rmx_ypbm,B.rmx_bzgg,B.rmx_dw,B.rmx_jj,B.rmx_pfj,
	               	    B.rmx_lsj,B.rmx_sl,B.rmx_ph,B.rmx_rxrq,B.rmx_hw,B.rmx_cj,A.rkd_rq,
                            B.rmx_otcj , B.rmx_xydj , A.rkd_ckdh , B.rmx_scrq
		            FROM yk_rkd A,inserted B
		            WHERE B.rmx_dh=A.rkd_num


   DECLARE avg_cursor SCROLL CURSOR 
     FOR SELECT rmx_ypbm , rmx_bzgg,rmx_fph,rmx_je,rmx_dh,rmx_pfj,rmx_sl FROM inserted
   OPEN avg_cursor
   FETCH NEXT FROM avg_cursor INTO @vypbm , @vbzgg,@vfph,@vje,@vdh,@vpfj,@vsl
   WHILE (@@fetch_status <> -1)
     BEGIN 
       IF (@@fetch_status <> -2) 
       BEGIN
          EXECUTE msp_avg @vypbm , @vbzgg
          SELECT @vlb = ( SELECT rkd_lb FROM yk_rkd WHERE rkd_num=@vdh)
          SELECT @vdwbm = ( SELECT rkd_hy FROM yk_rkd WHERE rkd_num=@vdh GROUP BY rkd_hy)
          SELECT @vfkrq = ( SELECT rkd_fkrq FROM yk_rkd WHERE rkd_num=@vdh GROUP BY rkd_fkrq)
	  IF @vlb = 'RK'
          BEGIN
	    IF  @vfph IS NOT NULL
              BEGIN
	          SELECT @vrowcount = (SELECT COUNT(*) FROM yk_sfkz WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1')
	          IF @vrowcount > 0
	             UPDATE yk_sfkz SET sf_je = sf_je + @vje 
                               WHERE sf_dwbm=@vdwbm AND sf_fph=@vfph AND sf_flag='1'
	          ELSE
	             INSERT yk_sfkz(sf_fph,sf_dwbm,sf_je,sf_flag,sf_rq0)
	                VALUES(@vfph,@vdwbm,@vje,'1',@vfkrq)
	      END
            ELSE 
              BEGIN
	          SELECT @vrowcount = (SELECT COUNT(*) FROM yk_sfkz WHERE sf_dwbm=@vdwbm AND sf_flag='1' AND sf_fph='无发票')
	          IF @vrowcount > 0
	             UPDATE yk_sfkz SET sf_je = sf_je + @vje 
			WHERE sf_dwbm=@vdwbm AND sf_flag='1' AND sf_fph='无发票'
	          ELSE
	             INSERT yk_sfkz(sf_fph,sf_dwbm,sf_je,sf_flag,sf_rq0)
	                VALUES('无发票',@vdwbm,@vje,'1',@vfkrq)
	      END
          END  
       END
       FETCH NEXT FROM avg_cursor INTO @vypbm , @vbzgg,@vfph,@vje,@vdh,@vpfj,@vsl
     END 
   CLOSE avg_cursor
   DEALLOCATE avg_cursor
 INSERT INTO yk_mxz 
	SELECT 1,A.rkd_rq,B.rmx_ypbm,C.yp_mc,C.yp_gg,B.rmx_bzgg,C.yp_jkyp,B.rmx_dw,0,
               0,0,B.rmx_sl,B.rmx_jj, B.rmx_je,0,0,0,0,0,0,
               0,0,0,B.rmx_ph,B.rmx_rxrq,A.rkd_hy,D.dw_mc, B.rmx_num,0 , 0
            FROM yk_rkd A,inserted B , zdyp C , yk_gydw D
            WHERE B.rmx_dh=A.rkd_num AND B.rmx_ypbm = C.yp_bm AND D.dw_bm = A.rkd_hy




 END


GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[sys_userinfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[sys_userinfo]
GO

CREATE TABLE [dbo].[sys_userinfo] (
	[su_num] [int] IDENTITY (1, 1) NOT NULL ,
	[su_pcname] [char] (30) NULL ,
	[su_serialid] [char] (20) NULL ,
	[su_type] [tinyint] NOT NULL ,
	[su_comment] [char] (20) NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[sys_userinfo] WITH NOCHECK ADD 
	CONSTRAINT [DF_sys_userinfo_su_type] DEFAULT (0) FOR [su_type],
	CONSTRAINT [PK_sys_userinfo] PRIMARY KEY  NONCLUSTERED 
	(
		[su_num]
	)  ON [PRIMARY] 
GO

/*

   2004年4月9日 15:59:34

   User: sa

   Server: SQ

   Database: ykxt20

   Application: SQL Server Enterprise Manager

*/



BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
GO
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_gg_7__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_dw_5__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_dj_4__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_sl_11__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_sldw_12__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_zx_14__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_zf_13__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_dsy_3__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_qy_9__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_gljb_8__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_fylb_6__11
GO
ALTER TABLE dbo.zdyp
	DROP CONSTRAINT DF_zdyp_yp_sj_10__11
GO
CREATE TABLE dbo.Tmp_zdyp
	(
 	yp_bm char(20) NOT NULL,
	yp_dh char(20) NOT NULL,
	yp_mc char(50) NOT NULL,
	yp_emc char(30) NULL,
	yp_gg char(15) NOT NULL CONSTRAINT DF_zdyp_yp_gg_7__11 DEFAULT ('1'),
	yp_dw char(4) NOT NULL CONSTRAINT DF_zdyp_yp_dw_5__11 DEFAULT (' '),
	yp_dj numeric(8, 3) NOT NULL CONSTRAINT DF_zdyp_yp_dj_4__11 DEFAULT (0),
	yp_lb char(4) NULL,
	yp_sl numeric(8, 3) NOT NULL CONSTRAINT DF_zdyp_yp_sl_11__11 DEFAULT (1),
	yp_sldw char(4) NOT NULL CONSTRAINT DF_zdyp_yp_sldw_12__11 DEFAULT (' '),
	yp_zx bit NOT NULL CONSTRAINT DF_zdyp_yp_zx_14__11 DEFAULT (0),
	yp_zf bit NOT NULL CONSTRAINT DF_zdyp_yp_zf_13__11 DEFAULT (0),
	dsy bit NOT NULL CONSTRAINT DF_zdyp_dsy_3__11 DEFAULT (0),
	yp_qy bit NOT NULL CONSTRAINT DF_zdyp_yp_qy_9__11 DEFAULT (0),
	yp_gljb char(1) NOT NULL CONSTRAINT DF_zdyp_yp_gljb_8__11 DEFAULT ('9'),
	yp_fylb char(3) NOT NULL CONSTRAINT DF_zdyp_yp_fylb_6__11 DEFAULT ('XY'),
	yp_bz char(40) NULL,
	yp_sj smalldatetime NOT NULL CONSTRAINT DF_zdyp_yp_sj_10__11 DEFAULT (getdate()),
	yp_jkyp char(1) NULL,
	yp_bzwh char(20) NULL,
	yp_nz char(10) NULL,
	yp_zczh char(50) NULL,
	pfj numeric(8, 4) NULL,
	gfj numeric(8, 4) NULL,
	bz numeric(8, 4) NULL,
	cj nvarchar(15) NULL
	) ON [PRIMARY]
GO
IF EXISTS(SELECT * FROM dbo.zdyp)
	 EXEC('INSERT INTO dbo.Tmp_zdyp(yp_bm, yp_dh, yp_mc, yp_emc, yp_gg, yp_dw, yp_dj, yp_lb, yp_sl, yp_sldw, yp_zx, yp_zf, dsy, yp_qy, yp_gljb, yp_fylb, yp_bz, yp_sj, yp_jkyp, yp_bzwh, yp_nz, yp_zczh, pfj, gfj, bz, cj)
		SELECT yp_bm, yp_dh, yp_mc, yp_emc, yp_gg, yp_dw, yp_dj, yp_lb, yp_sl, yp_sldw, yp_zx, yp_zf, dsy, yp_qy, yp_gljb, yp_fylb, yp_bz, yp_sj, yp_jkyp, yp_bzwh, yp_nz, yp_zczh, pfj, gfj, bz, cj FROM dbo.zdyp TABLOCKX')
GO
ALTER TABLE dbo.yk_bzgg
	DROP CONSTRAINT FK___1__11
GO
ALTER TABLE dbo.yk_cgjh
	DROP CONSTRAINT FK___4__11
GO
ALTER TABLE dbo.yk_rkdmx
	DROP CONSTRAINT FK_yk_rkdmx_zdyp
GO
ALTER TABLE dbo.yk_pyk
	DROP CONSTRAINT FK___3__11
GO
ALTER TABLE dbo.yk_zz
	DROP CONSTRAINT FK___5__11
GO
ALTER TABLE dbo.yk_ckdmx
	DROP CONSTRAINT FK_yk_ckdmx_zdyp
GO
DROP TABLE dbo.zdyp
GO
EXECUTE sp_rename 'dbo.Tmp_zdyp', 'zdyp'
GO
ALTER TABLE dbo.zdyp ADD CONSTRAINT
	PK___1__11 PRIMARY KEY CLUSTERED 
	(
	yp_bm
	) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX I_zdyp_yp_dh ON dbo.zdyp
	(
	yp_dh
	) ON [PRIMARY]
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_ckdmx WITH NOCHECK ADD CONSTRAINT
	FK_yk_ckdmx_zdyp FOREIGN KEY
	(
	cmx_ypbm
	) REFERENCES dbo.zdyp
	(
	yp_bm
	)
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_zz WITH NOCHECK ADD CONSTRAINT
	FK___5__11 FOREIGN KEY
	(
	zz_ypbm
	) REFERENCES dbo.zdyp
	(
	yp_bm
	)
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_pyk WITH NOCHECK ADD CONSTRAINT
	FK___3__11 FOREIGN KEY
	(
	pyk_ypbm
	) REFERENCES dbo.zdyp
	(
	yp_bm
	)
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_rkdmx WITH NOCHECK ADD CONSTRAINT
	FK_yk_rkdmx_zdyp FOREIGN KEY
	(
	rmx_ypbm
	) REFERENCES dbo.zdyp
	(
	yp_bm
	)
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_cgjh WITH NOCHECK ADD CONSTRAINT
	FK___4__11 FOREIGN KEY
	(
	cgjh_ypbm
	) REFERENCES dbo.zdyp
	(
	yp_bm
	)
GO
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_bzgg WITH NOCHECK ADD CONSTRAINT
	FK___1__11 FOREIGN KEY
	(
	gg_ypbm
	) REFERENCES dbo.zdyp
	(
	yp_bm
	)
GO
COMMIT

/*

   2004年5月18日 18:32:52

   User: sa

   Server: SQ

   Database: Ykxt20

   Application: MS SQLEM - Data Tools

*/



BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
ALTER TABLE dbo.yk_rkdmx ADD
	rmx_ysrq smalldatetime NULL
GO
COMMIT


BEGIN TRANSACTION
INSERT INTO reportmoddw (winname , dwname) (SELECT DISTINCT reportmod.winname , reporttabledw.dwname FROM reportmod , reporttabledw , reportmodwin
		WHERE reportmod.winname = reportmodwin.winname AND
			reportmodwin.tablename = reporttabledw.tablename )
		
GO

INSERT INTO reportwindw VALUES (
	'd_rkmx_cx_ck',
	'cjmc',
	'生产厂家名称',
	'string',
	1)

GO

INSERT INTO reportwindw VALUES (
	'd_rkmx_cx',
	'cjmc',
	'生产厂家名称',
	'string',
	1)
GO

INSERT INTO reportwindw VALUES (
	'r_excel_ckmx',
	'yk_ckdmx_cmx_scrq',
	'生产日期',
	'string',
	1)

GO
COMMIT

