Showing posts with label base. Show all posts
Showing posts with label base. Show all posts

Thursday, March 29, 2012

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
Thanks
To duplicate the table columns and data, just:
SELECT * INTO Newtable FROM Oldtable
However this will not copy indexes, access privileges, etc.
To get everything you must script the table to create it, and then add the
data, perhaps with
INSERT INTO NewTable SELECT * FROM Oldtable
Of course, using column names instead of * would be a better practice.
Rick Byham (MSFT)
This posting is provided "AS IS" with no warranties, and confers no rights.
"Omar Abid" <omar.abid2006@.gmail.com> wrote in message
news:1181578789.815330.212000@.q69g2000hsb.googlegr oups.com...
> Hi,
> In my program i need to duplicate a table in a current data base.
> I'm thinkin' of reading the data base columns and then rows and so i
> create another table
> Is there any other easy and fast method with SQL Server 2005, because
> my idea is so slow
> I'm using VB 2005 Express with SQL Server 2005 Express
> Thanks
>
|||> INSERT INTO NewTable SELECT * FROM Oldtable
> Of course, using column names instead of * would be a better practice.
And might be necessary, e.g. for IDENTITY/ROWVERSION...
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
ThanksHi
On Jun 11, 5:19 pm, Omar Abid <omar.abid2...@.gmail.com> wrote:
> Hi,
> In my program i need to duplicate a table in a current data base.
> I'm thinkin' of reading the data base columns and then rows and so i
> create another table
> Is there any other easy and fast method with SQL Server 2005, because
> my idea is so slow
> I'm using VB 2005 Express with SQL Server 2005 Express
> Thanks
If you just want to create copy the data then you could use
SELECT *
INTO #temptable
FROM Mytable
Which will create a new table with the contents of the old table, but
the new table will not have the constraints such as primary or foreign
keys and indexes that the original table had. If you dont want the
table but just the columns use a where clause that will never be
satisfied such as
WHERE 1 = 0
Alternatively you can use SMO see Allen Whites posts in the thread
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876099&SiteID=1
John

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
Thanks
SELECT * INTO NewTable FROM OldTable
Andrew J. Kelly SQL MVP
"Omar Abid" <omar.abid2006@.gmail.com> wrote in message
news:1181578846.356369.101240@.n4g2000hsb.googlegro ups.com...
> Hi,
> In my program i need to duplicate a table in a current data base.
> I'm thinkin' of reading the data base columns and then rows and so i
> create another table
> Is there any other easy and fast method with SQL Server 2005, because
> my idea is so slow
> I'm using VB 2005 Express with SQL Server 2005 Express
> Thanks
>

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
Thanks
Hi
On Jun 11, 5:19 pm, Omar Abid <omar.abid2...@.gmail.com> wrote:
> Hi,
> In my program i need to duplicate a table in a current data base.
> I'm thinkin' of reading the data base columns and then rows and so i
> create another table
> Is there any other easy and fast method with SQL Server 2005, because
> my idea is so slow
> I'm using VB 2005 Express with SQL Server 2005 Express
> Thanks
If you just want to create copy the data then you could use
SELECT *
INTO #temptable
FROM Mytable
Which will create a new table with the contents of the old table, but
the new table will not have the constraints such as primary or foreign
keys and indexes that the original table had. If you dont want the
table but just the columns use a where clause that will never be
satisfied such as
WHERE 1 = 0
Alternatively you can use SMO see Allen Whites posts in the thread
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=876099&SiteID=1
John
sql

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
ThanksOmar Abid <omar.abid2006@.gmail.comwrote in news:1181578579.728121.204320
@.g4g2000hsf.googlegroups.com:

Quote:

Originally Posted by

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
Thanks
>
>


SELECT * INTO NewTable FROM OldTable|||On 11 juin, 18:54, "Chris.Cheney" <Chris.CheneyXXNOSPA...@.tesco.net>
wrote:

Quote:

Originally Posted by

Omar Abid <omar.abid2...@.gmail.comwrote in news:1181578579.728121.204320
@.g4g2000hsf.googlegroups.com:
>

Quote:

Originally Posted by

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
Thanks


>
SELECT * INTO NewTable FROM OldTable


Hi
Thx for your reply I'll try your code and submit the result to you
Omar Abid

Duplicate table

Hi,
In my program i need to duplicate a table in a current data base.
I'm thinkin' of reading the data base columns and then rows and so i
create another table
Is there any other easy and fast method with SQL Server 2005, because
my idea is so slow
I'm using VB 2005 Express with SQL Server 2005 Express
ThanksHi
On Jun 11, 5:19 pm, Omar Abid <omar.abid2...@.gmail.com> wrote:
> Hi,
> In my program i need to duplicate a table in a current data base.
> I'm thinkin' of reading the data base columns and then rows and so i
> create another table
> Is there any other easy and fast method with SQL Server 2005, because
> my idea is so slow
> I'm using VB 2005 Express with SQL Server 2005 Express
> Thanks
If you just want to create copy the data then you could use
SELECT *
INTO #temptable
FROM Mytable
Which will create a new table with the contents of the old table, but
the new table will not have the constraints such as primary or foreign
keys and indexes that the original table had. If you dont want the
table but just the columns use a where clause that will never be
satisfied such as
WHERE 1 = 0
Alternatively you can use SMO see Allen Whites posts in the thread
http://forums.microsoft.com/MSDN/Sh...876099&SiteID=1
John

Tuesday, March 27, 2012

Duplicate row using trigger

I have a database with a table that stores details about a computer base unit. This can be identified using a unique ID which is stamped on the top of each case.

Sometimes an old PC gets replaced with a new one, but the old monitor etc. are retained. It would be good to have a way of duplicating a row so that the records for the monitor etc. are updated to use the new unique ID. However, it would be good to have a copy of the old base units details copied into a record with its ID number.

I was thinking about doing this via. a trigger, does anybody have any better suggestions about how this may be done?

Thanks,
PaulU can use flag separate for identifying old and new.
depending on this u can use auto-incremented values each time.

it will be better if u can send me some sample data so that i can give u a better suggestion.