.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to copy a table record and all related table records linked via relationships...

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
Hi!I'm using SQL Server 2005 in a project, and i need to duplicate a record from a table and all it's relationships. Can this be done? If so, can anyone tel me how please.

View Complete Post

More Related Resource Links

Update records related to primary table in sql


HI All,

For example

I have 2 tables  Person and Person_Child.

In Person table i have columns

Id, PersonId,PersonName,PersonAdrress,PersonAge,RowId


rowid is identity


and in the person_child table--here parentrowid refers to parent table rowid and again rowid is identity here

Id, PersonId,PersonName,PersonAdrress,PersonAge,ParentRowid,RowId




I need to update the child table values as it is in parent tables where it is null.

I have to do for many tables.

Is there any way to do it dynamically.







You cannot add or change a record because a related record is required in table 'Member'.


Hi, I am using Table Adapter to insert records into my database. I first insert my member record into the database and it has no errors, after that i insert the contact records into the table. however I got the following error:

You cannot add or change a record because a related record is required in table 'Member'.

This is my code:

              For index = 0 To contactList.Items.Count - 1
            newContactRow.memberIc = memRow.nric
            newContactRow.number = CType(contactList.Items.Add(index), String)
            Contactdt = CType(ds.Contacts.GetChanges, dbDataSet.ContactsDataTable)
            If Contactdt IsNot Nothing Then
                    MsgBox("Contacts have been added into database")
                Catch ex As Exception

                End Try
            End If

Memdt = CType(ds.Member.GetChanges,dbDataSet.MemberDataTable)
        If Memdt IsNot Nothing Then
                MsgBox("Member has been added into database")
            Catch ex As Exception

Bulk Copy From Datatable To SQL Server Table


 I have read the data of a excle file and captured the data into the dataset to a datatable, now that data is to be inserted into a SQL Server table using bulk copy option. I am using -

 public bool BulkEnterData(DataTable dt, string tblName)
        SqlBulkCopy bulk = new SqlBulkCopy(con);
        bulk.DestinationTableName = tblName;

        return true;

ERROR Getting-
A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.) 

How to resolve the above problem or any other solution is available.


select max record to join another table sybase

select a.pono,(select (user) from user where userid=a.userid having date=max(date)) as user from a inner join b on a.no=b.no  in the result , i have selected the same id and retrieve two records every thing are same except the date how can i select the record out of two record which date is max date as the where Clasuse to select correct user poid    date                name 1        12/08/2010      Mary 1        20/08/2010      Peter   now i would like to select name which id=1 and date is max and then use the name to join another table because name is foreign key  

How to copy table data from test to production database

I'm using SQL Server 2008 R2 and I'd like to copy all data rows from one table of a test database to the identical table in a production database. The primary key of the table is referred to by other tables so a DELETE followed by a number of INSERTs won't do it because of referential integrity issues. What is the best method to replace the data rows in the destination database with the values from the source database? Thanks, Guido

Delete Record From Table A that Is Not In Table B

I have two tables; Table A id, name 101, jones 102, smith 103, williams 104, johnson 105, brown 106, green 107, anderson   Table B id, name, city, state 101, jones, des moine, Idaho 103, williams, Corvallis, Oregon 104, johnson, Grand Forks, North Dakota 105, brown, Phoenix, Arizona 107, anderson, New York, New York   I need to delete records from Table A that are not in Table B.  My front end is writen in .net and I am using Data Access Layer along with a Business Logic Layer for data interaction.   I have tried at least seven variations of joining, right outer join, left outer join resulting in wiping our the entire table or nothing at all; not to mention deleting the record that ought to remain and keeping the record that needs to be deleted!   In my BLL I tried to capture the rowsAffected for the deletion by using-without success. Dim rowsAffected As Integer = Adapter.ID_Deletion(ID) If rowsAffected = 1 Then Exit Function Else Return rowsAffected = 1 End If   Please help.   MsMe.

Duplicate records find in table

  Hi ALL, I want to find the dynamically check the primary key values and remove the duplicate records.. please suggest it.   Regards Ram

How to send record(which is a weblink) from a table to the value of the variable in SSIS package and

Hi Folks, I have table called Table1 with columns, col1 and col2 with col1 having weblinks for the report and col2 the name of the report. Now, i have a package with a variables var1 and var2 which should get the col1 and col2 values respectively from table1 and send it through an email. if the weblink gets updated in the table, package should send the updated link. i know the reverse way of it but trying to do somethig like this. Appreciate any help from you guys. Thanks

Selecting different no. of records from the same table

Hello all, This might seem a basic thing but bothering me from last few days. Suppose I have a table containing 5 million records and I am running queries one by one (one query executes completly and then next query is fired)as below on that table. SELECT top 20000 FROM MyTable SELECT top 200000 FROM MyTable SELECT top 2000000 FROM MyTable  Now my questions are; Will SQL Server use same execution plan? As I am running these queries one by one in same order as given above, will second query take less time than it should if run standalone (only second query is fired, no query fired before that) and similarly will third query take less time than it should if run standalone (only third query is fired, no query fired before that), since there is a possibility of same execution plan being used?  Regards.    

Record is already exists in Dimension table but still Kimball SCD Component is Identifying it as a n

Hi I have loaded Dimension table. Now even if the record already exists in my dimension table , every time I run package Kimball method SCD component is identifying as a new record. Please advise. Thanks, Anuja

I have relation many to many - how can I delete records from intermediate table ?

I have tables: Books id title Authors id name BooksAuthors book_id author_id Entity Framework generated only models for tables Books and Authors in relation many to many. How can I delete from table BooksAuthors all records where book_id =5 ?

Get the count of the recently added records to a table

i need to create 2 temporary tables. The records inserted into the 2nd table is the same as that from table1. Now, i am inserting some other records into table 2.what i need is, to retrieve the count of the recently added records into table2.How to achieve this? 

InfoPath repeating table Copy values from above row without Code

Hi, I have situation, where I want to copy the values from the above row to the newly created row in a Repeating table. Ex. I have a repeating table with 3 columns ID-Name-FileName. When I enter a data like 1-Customer1-File1.zip and hit "Insert new row", the new row should automatically populate the values of the above row. How can I do it without .Net code. Regards,

Cannot Insert records in table using NHibernate

I am very much new with NHibernate. I am inserting a new record in the table. However, it seems that it does not insert. What I'm using is Fluent NHibernate.Below is the code which inserts records. public virtual void Save(string CreatedBy) { ISession NHSession = Star.CNPL_BusinessObjects.Common.Session.OpenSession(); ITransaction NHTransaction = NHSession.BeginTransaction(); try { this.Save(CreatedBy, NHSession); NHTransaction.Commit(); NHSession.Flush(); } catch (Exception ex) { NHTransaction.Rollback(); throw ex; } } public virtual void Save(string CreatedBy, ISession Session) { try { if (this.IsPersisted) { this.SaveAuditTrail(Session, false, CreatedBy); Session.SaveOrUpdateCopy(this); } else { Session.Save(this); } } catch (Exception ex) { throw ex; } }

copy the image from table to disk drive

i have 2000  image he saved in the table "Employee" and i want to copy this pictures from table to diskdrive and save file name by the ID

Cannot add record in table using NHibernate

Hi there!I'm new to NHibernate and I need help on this issue.No records where inserted in my SQL Table after committing the transaction or after the .Flush() method. I checked the code and it follows the correct sequence of codes. I can't seem to find any other way where the error fails.

Upload millions of file records to a table

I have six input files having millions of record. I need to upload these data to my table. How can I upload the details in the most efficient way. Any help on this will be greatly appreciated.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend