Creating A Duplicate Row?

Sep 17, 2013

I have a table that I'll call 'places'. This is a table of places to visit and might look like this:

id (autoincrement), name, town, latitude, longitude, etc1, etc2, description

1, My barn, Toronto, 43.44, -79,443, y, n, "Country barn"

2, run down house, 46.4432, -79.4322, y, y, "this is an old house that seems to have been forgotten"

4, parking lot, 45.4322, -80,4333, n, n, "An vacant parking lot, overrun with grass"

I'm trying to implement a 'revert' feature sort of like Wikipedia's (Undo) where if someone vandalizes an entry in the table I can revert it. People can edit the description and latitude, longitude. The ID and name generally stay the same.

I'd like to copy the entire row (about 20 columns in a single row, I didn't list them all) to a temporary table or new row. I think using a new row in the same table might not be a good idea because it would cause the autoincrement ID to increase and I plan to delete the temp row when done with it anyway. Don't want too many gaps in the ID field.

Basically I want to have a script (I'll code it myself) that I can approve or disprove the changes to the row. If the changes are invalid (someone has put bad info in, erased the GPS fields, etc) then I just delete the temporary row and nothing changes.

If it's a valid change then I'd have to do something like an UPDATE to update the original row with the info from the temp table.

eg. OLD data from 'places'

2, run down house, 46.4432, -79.4322, y, y, "this is an old house that seems to have been forgotten"

NEW data put into 'places' via UPDATE command:

2, run down house, 46.4342, -79.4222, y, y, "this is an old house that seems to have been forgotten. I have fixed the GPS data that was inauurate."

So it's a matter of updating the old row and deleting the temp table afterwards. I'm not familiar with stored functions or routines in SQL. I use Server Management Studio but only for running queries and viewing the columns - I don't know how to store any routines in the database.

All my code is done simply by sending strings to SQL from Active Server:

sqlst = "insert into table <whatever>"
Set objRs = objCmd.Execute(sqlst)

So if it's possible to accomplish this just through executing a few queries, great. Otherwise I might have to learn how to do a stored routine in SQL.

View 3 Replies


ADVERTISEMENT

Creating (almost) Duplicate Rows

Aug 6, 2004

Hi everyone, I'm migrating some information for a client at the moment. They had everything in Excel files and I'm getting them into SQL Server. There are some differences in the way I am storing data and the way they were storing data.

For each client they stored, they had something like
Rel1 Rel2 Rel3
100 101 102

Now, what I have is a seperate row for each of Rel1, Rel2 and Rel3 so I would have 3 seperate rows with identical information except for Rel1. So I would have:
Rel1
100
101
102

So one way I thought of doing it was inserting a new row specifying that the value for Rel2 should be stored in Rel1 and for the next row that the value for Rel3 should be stored in Rel1.

Now, I am able to do this but SQL Server inserts an extra row will the NULL value in Rel1. Does anyone know why this would be happening? I think what it is doing is finding a NULL value in Rel3 after creating the two extra rows and is inserting that NULL. So I think I need to check for NULLs and not allow it to create a new row if, say, Rel3 is NULL.

Any pointers are gladly welcome. (I know it's complicated )

View 1 Replies View Related

Creating Duplicate Database

Aug 8, 2006

Instead of me testing my scripts on my main commerce database I was wondering if there was an easy way to duplicate my most currnet database as another database...

that way if I screw up I can just delete it and try again

I looked at the restore as in enterpirse manager, but I don't think thats it

View 4 Replies View Related

Creating Duplicate Table

Dec 12, 2006

ravi writes "plz tell me code for
1. i want to create a table with same structure and key value as an existing table.

2. How can i modify the primary key there i new table"

View 1 Replies View Related

Creating Duplicate Table

Aug 9, 2007

Please Help me... How to create duplicate table dynamically(In Code). I have written query like this... select * into table2 from table1. But this creates only structure and data. I need to create along with constraints also(Primary key, default,index). Please help out me....

View 12 Replies View Related

Syntax For Creating Duplicate Table

Nov 29, 2000

Hi
Is there a syntax similar to the oracle in SQL Server?
Oracle statement: create table table2 as select * from table1

which will create table2 with exactly the same structure
and records as table 1

thanks
Liju

View 2 Replies View Related

Creating Duplicate Databases Daily

Nov 6, 2005

I want to be able to create a duplicate database and update / refresh it daily automatically. This database copy would be used for testing purposes so I don't want it to write back to the original database. Is replication of some kind the answer?

View 4 Replies View Related

Reporting Services :: SSRS Subscription Creating Duplicate Job

Jan 4, 2012

We have this sporadic problem where when we go in to save an edit on a SSRS report subscription, it gives us a duplicate job number error.  When I look at the Jobs in the Agent, there are duplicates, so I need to manually delete both duplicate jobs, then the subscription save will work.  If we delete just 1 of the jobs, the issue seems to clear for a while, but then reoccurs.  This has happened to us on multiple reports, but not consistently.  The subscriptions look fine.

View 7 Replies View Related

CREATE TABLE DUPLICATE OBJECT/DUPLICATE FIELD NAME ERROR Msg 2714

Oct 2, 2007

Hello Everyone:

I am using the Import/Export wizard to import data from an ODBC data source. This can only be done from a query to specify the data to transfer.

When I try to create the tables, for the query, I am getting the following error:




Msg 2714, Level 16, State 4, Line 12

There is already an object named 'UserID' in the database.

Msg 1750, Level 16, State 0, Line 12

Could not create constraint. See previous errors.


I have duplicated this error with the following script:


USE [testing]

IF OBJECT_ID ('[testing].[dbo].[users1]', 'U') IS NOT NULL

DROP TABLE [testing].[dbo].[users1]

CREATE TABLE [testing].[dbo].[users1] (

[UserID] bigint NOT NULL,

[Name] nvarchar(25) NULL,

CONSTRAINT [UserID] PRIMARY KEY (UserID)

)

IF OBJECT_ID ('[testing].[dbo].[users2]', 'U') IS NOT NULL

DROP TABLE [testing].[dbo].[users2]

CREATE TABLE [testing].[dbo].[users2] (

[UserID] bigint NOT NULL,

[Name] nvarchar(25) NULL,

CONSTRAINT [UserID] PRIMARY KEY (UserID)

)

IF OBJECT_ID ('[testing].[dbo].[users3]', 'U') IS NOT NULL

DROP TABLE [testing].[dbo].[users3]

CREATE TABLE [testing].[dbo].[users3] (

[UserID] bigint NOT NULL,

[Name] nvarchar(25) NULL,

CONSTRAINT [UserID] PRIMARY KEY (UserID)

)



I have searched the "2714 duplicate error msg," but have found references to duplicate table names, rather than multiple field names or column name duplicate errors, within a database.

I think that the schema is only allowing a single UserID primary key.

How do I fix this?

TIA

View 4 Replies View Related

The Package Contains Two Objects With The Duplicate Name - Package Created In UI - Duplicate Columns

Aug 17, 2007

I've begun to get the above error from my package. The error message refers to two output columns.



Anyone know how this could happen from within the Visual Studio 2005 UI? I've seen the other posts on this subject, and they all seemed to be creating the packages in code.

Is there any way to see all of the columns in the data flow? Or is there any other way to find out which columns it's referring to?
Thanks!

View 3 Replies View Related

Creating Trigger On Creating Table

Jan 28, 2008



Hi,

If I want to automatically insert a record which has default value in a table,
how can I create the trigger?

View 5 Replies View Related

Creating A New User For Sp Execution Say Sa (to Whom I Am In Need Of Creating Under My User Defined Db )

Jul 11, 2007

I am in need of creating a new user for stored procedures execution say sa (to whom i am in need of creating under my user defined db)

View 1 Replies View Related

Duplicate Key

Mar 9, 2001

Hi,
The DTS or jobs failed due to the ignore duplicate key message. How do
I turn this dup key message off or ignore it so that the jobs will succeed?


thanks,
Rachel

View 1 Replies View Related

Duplicate Row

Apr 22, 1999

How can I compare numerous rows in the same table that have the same fname, lname and access_id but different identity values (and other columns) and then keep only the one row which is the most current based on a date col?

This seems so easy, but today I just can't come up with it. Do I have to use a cursor of some kind?

Troy

View 1 Replies View Related

Duplicate Ids

Jan 12, 2007

Hi guys

How can i get id which are duplicate in a table.

Thanks

View 1 Replies View Related

Duplicate Key Ignored !!!

Jun 21, 2006

Hi guys,

i have the following tables:

Table1:
[PKID] WITH INDEX "IGNORE DUPLICATE KEY"

Table2:
[FKID]


and i have the following SQL statement:

insert into Table1
select distinct FKID
from Table2
where FKID not in (select PKID from Table1)



The above SQL statement is in a DTS package which raises "Duplicate key ignored" error... i can't see how that can happen since i am already checking the key if it already exists. ..

Please help !!!

TNT :s

View 4 Replies View Related

Duplicate Key

Feb 10, 2007

Hi!
Very grateful for some advice... duplicate key.. but how do I solve it.
By Lookup ?
[OLE DB Destination [1647]] Error: An OLE DB error has occurred. Error code: 0x80040E2F. An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E2F Description: "The statement has been terminated.". An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E2F Description: "Violation of PRIMARY KEY constraint 'PK_Dim_Date'. Cannot insert duplicate key in object 'dbo.Dim_Date'.".

OLE db SQL: SELECT DISTINCT convert (char(8),date,112) as day, cast(datepart(year, date) as varchar(4)) + cast(datepart(week, date) as
varchar(2)) as weeknr, cast(datepart(year, date) as varchar(4)) + Substring(convert(varchar(10), date, 121), 6, 2) as month, YEAR(date) AS year FROM Purchase

View 5 Replies View Related

Duplicate Row's

Oct 25, 2007



I'm currently working on a Game DB, To where i can set Primary Key's and such, otherwise the Emu reads it wrong. The current table i am working on, has duplicate row's of every row. (3600 rows instead of 1800) and the duplicates have the same ID as the original row. How would i go about Deleting the Duplicate rows without harming the original? (Sql 2005)

Regards

Vision

View 1 Replies View Related

Duplicate Key Ignored

Mar 22, 2006

I have a stored procedure that inserts records into a table with a Unique Clustered Index with ignore_Dup_Key ON.

I can run the stored procedure fine, and get the message that duplicate keys were ignored, and I have the unique data that I want.

When I try to execute this in a DTS package, it stops the package execution because an error message was returned.

I have tried setting the fail on errors to OFF, but this has no effect.

I found the bug notification that says this was corrected with service pack 1, and have now updgraded all the way to service pack 4, and still get the issue.

I tried adding the select statement as described as a work-around in the bug, and still can't get it past the DTS.

I have verified the service pack, re-booted, etc.....

I am trying this in MSDE 2000a.

Thoughts or comments? Thanks!

View 4 Replies View Related

Can I Duplicate Data?

Dec 11, 2006

Hello guys! Is it possible to duplicate a primary key?
I would like my database to accept data with the same primary key.
Is it possible?
How do you declare ON DUPLICATE KEY UPDATE?
Please help me. Thanks in advance.  

View 1 Replies View Related

How To Avoid Duplicate Value

Mar 2, 2007

Hello,

I have the following query,

SELECT GroupInfo.GroupID, GroupInfo.GroupName
FROM GroupInfo INNER Join DeviceGroup ON(DeviceGroup.GroupID=Groupinfo.GroupID)
INNER Join Deviceinfo ON (Deviceinfo.SerialNumber=DeviceGroup.SerialNumber )

It's out put is as follow:

Group ID GroupName
0 Abc
1 Beta
0 Abc
0 Abc
0 Abc
1 Beta
2 Alpha

Now, I want to make such query which will give me result as a Group ID and Group Name but not in repeating manner, Like,


Group ID GroupName
0 Abc
1 Beta
2 Alpha

Hope I explained what I need to see in result pane.

Thanks,

Junior

View 1 Replies View Related

No Duplicate Value In The Column?

Feb 15, 2008

 hello everyone, how to prevent putting same value into the column in the sqldatabase? while inserting value into the table from asp.net page dynamically,i dont want user to insert same  data again and again. is there anyway i can make check the column in the database to look for the duplication value. if not then only i want to make it insert. thanks. jack. 

View 1 Replies View Related

Duplicate A Row Of Data MS Sql

Jul 1, 2004

I want to be able to duplicate a row of data in sql....Does anyone know if there is a sql command that will do that. I have a table with an auto increment primary key and I want to duplicate everything except the key into a new record.

Thanks.

View 2 Replies View Related

DUPLICATE ROWS

Jun 25, 2001

I used the following select statement to get duplicate records on Case_number column

select cases.distinct case_link, cases.case_number
from cases
group by case_link
having case_number > 1

I got the error message that

"'cases.warrant_number' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
AND
cases.case_number' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.


Any idea on a better statement to use. THANKS FOR YOUR HELP!

View 3 Replies View Related

Duplicate Rows

Jun 29, 2001

Hi,
I have a table and this is what i did to get the desired result

Select A.col1,count(A.col1)
from Tab1
group by col1
having count(A.Col1) > 1

i tried this - but it didnot worked - it returned col1 as blanks -
Select A.col1,B.Col2,count(A.col1)
from Tab1 A, Tab2 B
where A.col1 = B.col1
group by A.col1 , b.col2
having count(A.Col1) > 1

As I was looking for all the rows that are apperaing more than once.

Now - The problem -

I have to join this table to another table Tab2 to get the other details.
My Tab2 is a table from where I have to pull the Customer DEtails like name,address etc.
How should I write this query?
Any thinuhts?
TIA

View 1 Replies View Related

UNION And Duplicate

Apr 5, 2000

When you perform a union between table A and table B which table is the duplicate eliminated from? BOL says they are removed but it does not specify how it chooses which to delete.

View 1 Replies View Related

Duplicate Indexes

Jan 24, 2001

Hi all,

I've just "inherited" a 7-year-old DB running SQL 7.0, and I've noticed that for some reason, there are several single column indexes where the column is also referenced in other, composite indexes. Now, I'm a pretty new DBA, so I want to know, what are the advantages/perils of removing the redundant single column indexes?

View 1 Replies View Related

BCP IN (Duplicate Key Error)

Apr 17, 2002

I'm running a BCP IN to a table that has a unique index with ignore duplicate key. I'm getting the error 'Duplicate Key was ignored', but my bcp is immediately failing. I'm importing about 6.8 million recs and I've set my maxerror switch to 7 million. Can anyone tell me how I can make the bcp ignore the dup. key error and continue running?

View 1 Replies View Related

Duplicate Records

Jan 18, 2000

Is there a way to find duplicate records in a table using code. We have about 500,000 records in this table.
Thanks.

View 1 Replies View Related

Eliminate Duplicate

Jul 29, 2003

Table A

JobNoClaimShipType
A1100I
A1200II

Table B

JobNoCost
A150
A1100

Result Expected


JobNOCost Claim Shiptype
A150 100I
A1100 200II

Hi all,
i've given a table structure with data
and the expected result .
I want to establish it in SQL server (7.0)
If i establish the inner join i get 4 rows (2*2)
Please let me know how to get the result
Thanx in adv
Tarriq

View 1 Replies View Related

Duplicate Records

Jan 27, 2005

Hi All,

How to check for the duplicate records in the table? Thanks.

View 1 Replies View Related

Duplicate Records

Jun 12, 2002

Yes, I know this subject has been exhausted, but I need help in locating the discussion which took place a few months ago.
Sharon relayed to the group a piece of software (expensive) which would help in my particular situation. I grabbed a demo and have gotten the approval for purchase. Unfortunately, I don't have the thread with me at work.

The problem:

Number Fname Lname Age ID
123 John Franklin 43 1
123 Jane Franklin 40 2
123 Jeff Franklin 12 3
124 Jean Simmons 39 4
125 Gary Bender 37 5
126 Fred Johnson 29 6
126 Fred Johnson 39 7
127 Gene Simmons 47 8

The idea would be to get only unique records from the Number column. I don't care about which information I grab from the other columns, but I must have those fields included.
If my resultant result set looked as follows, that would be fine. Or any other way, as long as all of the fields had information and there were only unique values in the Number field.

Number Fname Lname Age ID
123 Jeff Franklin 12 3
124 Jean Simmons 39 4
125 Gary Bender 37 5
126 Fred Johnson 39 7
127 Gene Simmons 47 8

If anyone remembers this discussion, mainly the date, I would really appreciate it.

Thanks

Gregory Taylor
MIS Director
Timeshares By Owner

View 1 Replies View Related

Duplicate Data?

Nov 17, 1998

I am new to SQL server 6.5.

I will need to stress test a sql server 6.5 test database by duplicating
data. To do so, I need to know how to modify the primary key(which are
numbers in character data type) to duplicate the data several times over.
The primary key is character data.

What I have done ion the past is use insert statments -let's say 20 -- and then copy them and change the date in a text editor and change the primary key column and the other coluimns with thea replace of different letters and numbers. This is slow and tedious.

Does any one have a script I can run to do so?

Can I do this sql or do I need some sort of stored procedure? Any help
would be appreciated. Thanks.

DAvid Spaisman

would be greatly appreciated. THanks.

David Spaisman

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved