清空初始化所有数据

declare @trun_name varchar(500)

 declare name_cursor cursor for

--禁用外键

--select  'ALTER TABLE ['  + name +  '] NOCHECK CONSTRAINT  all '  from  sysobjects  a  where  a.xtype ='u'  order by name

--禁用触发器

--select  'ALTER TABLE ['  + name +  '] DISABLE  TRIGGER  all '  from  sysobjects  a  where  a.xtype ='u'  order by name

--清空表

--select 'truncate table ' + name from sysobjects where xtype='U' and name not in ('xt_mksz','xt_mkczgn','xt_bmlb','xt_zdk','ps_yj_rgb','KH_YDKHZB','XT_BMGZ') order by name---,'xt_dwbm','xt_bmxx','xt_ryxxb','xt_jsb','xt_jsmxb','xt_user','xt_qxsz'

--开启外键

--select  'ALTER TABLE ['  + name +  '] CHECK CONSTRAINT  all '  from  sysobjects  a  where  a.xtype ='u'  order by name

--开启触发器

--select  'ALTER TABLE ['  + name +  '] enable  TRIGGER  all '  from  sysobjects  a  where  a.xtype ='u'  order by name

--所有identity表复原为1

--select  'dbcc checkident(['+name+'],reseed ,1) ' from  sysobjects  a  where  a.xtype ='u'  and objectproperty(id,'TableHasIdentity')=1  and name not in ('xt_bmlb','xt_zdk','ps_yj_rgb','XT_BMGZ') order by name--'xt_dwbm','xt_bmxx','xt_ryxxb','xt_jsb','xt_jsmxb','xt_user','xt_qxsz'

--重建索引

--select  'dbcc DBREINDEX(['+name+']) '  from  sysobjects  a  where  a.xtype ='u'   order by name  



 open name_cursor

 fetch next from name_cursor into @trun_name

 while @@FETCH_STATUS = 0

 begin

   exec (@trun_name)   

  print @trun_name

  fetch next from name_cursor into @trun_name

 end

 close name_cursor

 deallocate name_cursor

 

 /*

 --清空所有数据表后初始化系统设置

 INSERT INTO xt_dwbm(companyID,companyName,dwbm,trade,registerMoney,deleteSign)VALUES('20130001','洛阳市财政局','01','SSHY0001',0,0)

 INSERT INTO xt_bmxx(CompanyID,ID,Name,Scbz,Charger,Telephone)VALUES('20130001','001','投资评审中心','0','系统管理员','0')

 INSERT INTO xt_ryxxb(companyid,EmployeeID,Name,departmentID,sex,Scbz)VALUES('20130001','tzps001','系统管理员','001','男',0)

 INSERT INTO xt_jsb VALUES('001','系统管理员',0)

 INSERT INTO xt_jsmxb SELECT '001',ModuleID  FROM XT_MKSZ  

 INSERT INTO xt_user(userName,userPassword,realName,roleID,company,departmentCode,employeeID,Scbz)VALUES('admin','511B0D5F341BDDBD9A5348923B48D14C','系统管理员','001','20130001','001','bm001',0)

 INSERT INTO xt_qxsz SELECT (select TOP 1 id FROM xt_user WHERE userName='admin'),MKID,GNID FROM XT_MKCZGN 

 */

 


 

你可能感兴趣的:(初始化)