Problem With BackupDB for Deleted Info

  • I have two database AgencyDB(primary DB) and AgencyBackupDB(Deleted Info from AgencyDB by user) and i have this three table in both DB(but there is no relationship between Tables in AgencyBackupDB ).

    I get confused when I Want to restore Info From AgencyBackupDB to AgencyDB because the sabtHazine Table Have Foreign Key From Hazine And Hazine Also Have foreign Key from HazineGroup.how Can I restore my Info of sabtHazine to AgencyDB???????????? this is my table with test data

    CREATE TABLE [dbo].[HazineGroup](

    [HazineGroupID] [smallint] IDENTITY(1,1) NOT NULL,

    [HazineName] [nvarchar](150) NOT NULL,

    CONSTRAINT [PK_HazineGroup] PRIMARY KEY CLUSTERED

    (

    [HazineGroupID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],

    CONSTRAINT [IX_HazineGroup] UNIQUE NONCLUSTERED

    (

    [HazineName] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    SET IDENTITY_INSERT [dbo].[HazineGroup] ON

    INSERT [dbo].[HazineGroup] ([HazineGroupID], [HazineName]) VALUES (6, N'برق')

    INSERT [dbo].[HazineGroup] ([HazineGroupID], [HazineName]) VALUES (1, N'شستشویی')

    INSERT [dbo].[HazineGroup] ([HazineGroupID], [HazineName]) VALUES (2, N'نظافتی')

    SET IDENTITY_INSERT [dbo].[HazineGroup] OFF

    /****** Object: Table [dbo].[Hazine] Script Date: 04/07/2013 17:34:59 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[Hazine](

    [HazineID] [int] IDENTITY(1,1) NOT NULL,

    [HazineGroupID] [smallint] NOT NULL,

    [Mablagh] [int] NOT NULL,

    [HazineName] [nvarchar](250) NOT NULL,

    CONSTRAINT [PK_Hazine] PRIMARY KEY CLUSTERED

    (

    [HazineID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    SET IDENTITY_INSERT [dbo].[Hazine] ON

    INSERT [dbo].[Hazine] ([HazineID], [HazineGroupID], [Mablagh], [HazineName]) VALUES (1, 1, 20000, N'صابون گل')

    INSERT [dbo].[Hazine] ([HazineID], [HazineGroupID], [Mablagh], [HazineName]) VALUES (3, 2, 10000, N'بروس')

    SET IDENTITY_INSERT [dbo].[Hazine] OFF

    /****** Object: Table [dbo].[SabtHazine] Script Date: 04/07/2013 17:34:59 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[SabtHazine](

    [SabtHazineID] [int] IDENTITY(1,1) NOT NULL,

    [HazineID] [int] NOT NULL,

    [EndUserName] [nvarchar](20) NOT NULL,

    [Tedad] [smallint] NOT NULL,

    [sabtHazineDate] [date] NOT NULL,

    [Describtion] [nvarchar](500) NULL,

    CONSTRAINT [PK_SabtHazine] PRIMARY KEY CLUSTERED

    (

    [SabtHazineID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    SET IDENTITY_INSERT [dbo].[SabtHazine] ON

    INSERT [dbo].[SabtHazine] ([SabtHazineID], [HazineID], [EndUserName], [Tedad], [sabtHazineDate], [Describtion]) VALUES (6, 3, N'SA', 3, CAST(0xC2360B00 AS Date), N'

    ')

    SET IDENTITY_INSERT [dbo].[SabtHazine] OFF

    /****** Object: Default [DF_SabtHazine_Tedad] Script Date: 04/07/2013 17:34:59 ******/

    ALTER TABLE [dbo].[SabtHazine] ADD CONSTRAINT [DF_SabtHazine_Tedad] DEFAULT ((1)) FOR [Tedad]

    GO

    /****** Object: ForeignKey [FK_Hazine_HazineGroup] Script Date: 04/07/2013 17:34:59 ******/

    ALTER TABLE [dbo].[Hazine] WITH CHECK ADD CONSTRAINT [FK_Hazine_HazineGroup] FOREIGN KEY([HazineGroupID])

    REFERENCES [dbo].[HazineGroup] ([HazineGroupID])

    GO

    ALTER TABLE [dbo].[Hazine] CHECK CONSTRAINT [FK_Hazine_HazineGroup]

    GO

    /****** Object: ForeignKey [FK_SabtHazine_Hazine] Script Date: 04/07/2013 17:34:59 ******/

    ALTER TABLE [dbo].[SabtHazine] WITH CHECK ADD CONSTRAINT [FK_SabtHazine_Hazine] FOREIGN KEY([HazineID])

    REFERENCES [dbo].[Hazine] ([HazineID])

    GO

    ALTER TABLE [dbo].[SabtHazine] CHECK CONSTRAINT [FK_SabtHazine_Hazine]

    GO

  • plz sm help

  • How are you restoring the information from one database to the other? You can't insert any rows into AgencyDB that would violate any constraints in that database. If the data in your backup database violates any constraints, you'll need to clean it up before, or as part of, moving the data. Also, you'll need to populate parent tables before child tables where there are foreign key constraints.

    John

  • in my AgencyBackupDB there is no Constraint and when I delete Info From SabtHazine table In AgnecyDB. how can i Delete This Info that I face with No problem For Moving It back To AgencyDB.bacaues It have ForeignKey with another Table In AgnecyDB

  • As I said before, clean up the data before it goes into AgencyDB so that it doesn't violate the constraints. If you need more detailed help than that, please provide clear examples of what you're trying to do and what error messages you're getting.

    John

  • i have deleted Info From a table thay have foreign Key in AgencyDB and It Move To AgencyBackupDB.this my problem:

    how can i understand That Info that Move to AgencyBackupDB when i want to restore or move it back to AgencyDB foregin Key in table is the exact INFo.

    for example:

    table A:TblA_ID(int PK) FullName(Nvarchar(250))

    table B=TblB_ID(int PK) TblA_ID (ForeignKey from table A)

    i insert this data:

    table A:100, Bil Gates

    table B:1,100

    then user Delete Info of table B and it goes To BackupDB.after that I cleanup My DataBase and insert Info To DB:

    table A:100, Steve Jobs

    table B:1,100

    i want to restore Info From BackupDB foreign Key ID is Correct But Info is Incorrect.what can I DO?

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply