Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

table copy

 
   Database Forums (Home) -> General Discussions RSS
Next:  Query Assistance Needed - Please  
Author Message
GTi

External


Since: Nov 01, 2005
Posts: 3



(Msg. 1) Posted: Thu Oct 12, 2006 1:26 am
Post subject: table copy
Archived from groups: comp>databases>ms-sqlserver (more info?)

I have two identical tables with one IDENTITY column and several other
columns.
I have tested the COPY * INTO table2 FROM table1 WHERE xx
but it requers that table2 does not exist.
TABLE2 is a history database of TABLE1
How can I copy row(s) from table1 to table2 without conflict with
IDENTITY columns using SQL query.
Or must I do this from a program (C# .NET)

 >> Stay informed about: table copy 
Back to top
Login to vote
GTi

External


Since: Nov 01, 2005
Posts: 3



(Msg. 2) Posted: Thu Oct 12, 2006 5:40 am
Post subject: Re: table copy [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Dan Guzman wrote:
> > How can I copy row(s) from table1 to table2 without conflict with
> > IDENTITY columns using SQL query.
>
> If you want to let SQL Server assign new identity values during the insert,
> simply specify a column list and omit the identity column. For example:
>
> INSERT INTO dbo.table2(MyColumn)
> SELECT MyColumn
> FROM dbo.table1
>
> If you want to include the identity column values from the source table,
> specify IDENTITY_INSERT and include the identity column in the column list:
>
> SET IDENTITY_INSERT dbo.table2 ON
>
> INSERT INTO dbo.table2(MyIdentityColumn, MyColumn)
> SELECT MyIdentityColumn, MyColumn
> FROM dbo.table1
>
> --
> Hope this helps.
>
> Dan Guzman
> SQL Server MVP
> "GTi" wrote in message
>
> >I have two identical tables with one IDENTITY column and several other
> > columns.
> > I have tested the COPY * INTO table2 FROM table1 WHERE xx
> > but it requers that table2 does not exist.
> > TABLE2 is a history database of TABLE1
> > How can I copy row(s) from table1 to table2 without conflict with
> > IDENTITY columns using SQL query.
> > Or must I do this from a program (C# .NET)
> >

> Hope this helps.
Not directly, but u pointet me the directons.
My main problem is that I don't have full control over the colums, only
the basic ones.
Users may add new columns "on the run".
But as I now see it I do it in my c# .NET program. Retrieving all the
columns names and build the query you give me.

Thanks.

 >> Stay informed about: table copy 
Back to top
Login to vote
Dan Guzman1

External


Since: Aug 22, 2004
Posts: 469



(Msg. 3) Posted: Thu Oct 12, 2006 12:10 pm
Post subject: Re: table copy [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> How can I copy row(s) from table1 to table2 without conflict with
> IDENTITY columns using SQL query.

If you want to let SQL Server assign new identity values during the insert,
simply specify a column list and omit the identity column. For example:

INSERT INTO dbo.table2(MyColumn)
SELECT MyColumn
FROM dbo.table1

If you want to include the identity column values from the source table,
specify IDENTITY_INSERT and include the identity column in the column list:

SET IDENTITY_INSERT dbo.table2 ON

INSERT INTO dbo.table2(MyIdentityColumn, MyColumn)
SELECT MyIdentityColumn, MyColumn
FROM dbo.table1

--
Hope this helps.

Dan Guzman
SQL Server MVP
"GTi" wrote in message

>I have two identical tables with one IDENTITY column and several other
> columns.
> I have tested the COPY * INTO table2 FROM table1 WHERE xx
> but it requers that table2 does not exist.
> TABLE2 is a history database of TABLE1
> How can I copy row(s) from table1 to table2 without conflict with
> IDENTITY columns using SQL query.
> Or must I do this from a program (C# .NET)
>
 >> Stay informed about: table copy 
Back to top
Login to vote
Madhivanan

External


Since: Feb 28, 2005
Posts: 13



(Msg. 4) Posted: Sat Oct 14, 2006 9:07 pm
Post subject: Re: table copy [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

>>Users may add new columns "on the run".

Why?
That doesnt sound a good design

Madhivanan


GTi wrote:
> Dan Guzman wrote:
> > > How can I copy row(s) from table1 to table2 without conflict with
> > > IDENTITY columns using SQL query.
> >
> > If you want to let SQL Server assign new identity values during the insert,
> > simply specify a column list and omit the identity column. For example:
> >
> > INSERT INTO dbo.table2(MyColumn)
> > SELECT MyColumn
> > FROM dbo.table1
> >
> > If you want to include the identity column values from the source table,
> > specify IDENTITY_INSERT and include the identity column in the column list:
> >
> > SET IDENTITY_INSERT dbo.table2 ON
> >
> > INSERT INTO dbo.table2(MyIdentityColumn, MyColumn)
> > SELECT MyIdentityColumn, MyColumn
> > FROM dbo.table1
> >
> > --
> > Hope this helps.
> >
> > Dan Guzman
> > SQL Server MVP
> > "GTi" wrote in message
> >
> > >I have two identical tables with one IDENTITY column and several other
> > > columns.
> > > I have tested the COPY * INTO table2 FROM table1 WHERE xx
> > > but it requers that table2 does not exist.
> > > TABLE2 is a history database of TABLE1
> > > How can I copy row(s) from table1 to table2 without conflict with
> > > IDENTITY columns using SQL query.
> > > Or must I do this from a program (C# .NET)
> > >
>
> > Hope this helps.
> Not directly, but u pointet me the directons.
> My main problem is that I don't have full control over the colums, only
> the basic ones.
> Users may add new columns "on the run".
> But as I now see it I do it in my c# .NET program. Retrieving all the
> columns names and build the query you give me.
>
> Thanks.
 >> Stay informed about: table copy 
Back to top
Login to vote
GTi

External


Since: Nov 01, 2005
Posts: 3



(Msg. 5) Posted: Sun Oct 15, 2006 1:30 am
Post subject: Re: table copy [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Madhivanan wrote:
> >>Users may add new columns "on the run".
>
> Why?
> That doesnt sound a good design
>
> Madhivanan
>
After you have designed your tables and it have been deployed for some
time, have you never added more columns after updates?
Have you never wanted one more column on a 3. party table?
I always design my programs and tables so I or the customer can add
extra columns without program failure.
 >> Stay informed about: table copy 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Synchronous Bulk-Copy into two table - Hi guys, in my db i have these three tables 1.Stores 2.Products 3.Parts their structure is something like : Stores ----> Products ----> Parts Stores ---------------- StoreId, StoreName Products ---------------- ProductId, StoreId, Produ...

Copy data from one table to another table with change in i.. - HI, I have a table Create table test(a int identity(1,1), b int) insert into test(b) values(12) insert into test(b) values(30) insert into test(b) values(65) insert into test(b) values(78) insert into test(b) values(36) o/p a b 1 12 2 30 3 65 4 78...

working with a local db copy - Hi, I have copied a MS SQL database to my local machine and am testing it with ASP pages, locally, on IIS. I have a db connect page that keeps the current connections for the live database. My question is, as the local db is named 'local,' is there..

Primary Key fails to copy in db Export - Currently, I'm exporting a database from production to local (test) machine. I've done this several times without problem, but during the last few days, the primary keys have failed to export. Would anyone know what options might keep the keys from..

Create Table with Variable included in Table Name - Hi, I am trying to create a routine for generating tables from a master response table. The end result would increment the variable "somevalue" by one and then create the next table (ie: TESTTEST2). Is there a way to insert the variable into...
   Database Forums (Home) -> General Discussions All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]