Drop Table
Support Forum for database administrators and web based access to important newsgroups related to databasesOK, I create a table called Customer, I imported date from my as400, when i want to set a primary key it telling me that i have duplicate key. Keep in mind the layout of my table CustId, SubCustId, in CustId they can have more then one same CustId, but SubCustID have not the same SubCustID. example: CustId 68818 Sub 999, Cust 68818 Sub 618, as you can see custid can be the same but the sub is always different. Could anyone help me on tha t problem I have no more Idea. Thanks! JF
Post Follow-up to this messageSeem like the primary key should be the combination of CustId and SubCustId. -- Tibor Karaszi, SQL Server MVP http://www.karaszi.com/sqlserver/default.asp http://www. solidqualitylearning .com/ http://www.sqlug.se/ "Jean-Francois" < JeanFrancois@discuss ions.microsoft.com> wrote in message news:53D0FE4E-20C0-489D-8F26- C04C7568E454@microso ft.com... > OK, I create a table called Customer, I imported date from my as400, when i > want to set a primary key it telling me that i have duplicate key. > Keep in mind the layout of my table CustId, SubCustId, in CustId they can > have more then one same CustId, but SubCustID have not the same SubCustID. > > example: CustId 68818 Sub 999, Cust 68818 Sub 618, as you can see custid > can be the same but the sub is always different. Could anyone help me on t hat > problem I have no more Idea. > > Thanks! > JF
Post Follow-up to this messageIs the primary key defined on both columns? If it is, try to import the dat a over without the primary key, then check for duplicates. SELECT CustId, SubCustId FROM table GROUP BY CustId, SubCustId HAVING COUNT(*) > 1 "Jean-Francois" wrote: > OK, I create a table called Customer, I imported date from my as400, when i > want to set a primary key it telling me that i have duplicate key. > Keep in mind the layout of my table CustId, SubCustId, in CustId they can > have more then one same CustId, but SubCustID have not the same SubCustID. > > example: CustId 68818 Sub 999, Cust 68818 Sub 618, as you can see custid > can be the same but the sub is always different. Could anyone help me on t hat > problem I have no more Idea. > > Thanks! > JF
Post Follow-up to this messageI did SELECT CustId, SubCustId FROM table GROUP BY CustId, SubCustId HAVING COUNT(*) > 1 But it give me all my data. That seem to be that all my data is duplicate. I try to import the data before put the primary key and after put the primary key and get the same result. "Tibor Karaszi" wrote: > Seem like the primary key should be the combination of CustId and SubCustI d. > > -- > Tibor Karaszi, SQL Server MVP > http://www.karaszi.com/sqlserver/default.asp > http://www. solidqualitylearning .com/ > http://www.sqlug.se/ > > > "Jean-Francois" < JeanFrancois@discuss ions.microsoft.com> wrote in message > news:53D0FE4E-20C0-489D-8F26- C04C7568E454@microso ft.com... > > >
Post Follow-up to this messageHow many times have you try to import the data into SQL table? Did you delete all records in the table before you import the data if you did it multiple times? "Jean-Francois" wrote: > I did > SELECT CustId, SubCustId FROM table > GROUP BY CustId, SubCustId > HAVING COUNT(*) > 1 > > But it give me all my data. That seem to be that all my data is duplicate. > I try to import the data before put the primary key and after put the > primary key and get the same result. > > > "Tibor Karaszi" wrote: >
Post Follow-up to this messageI first delete the table and start over every time. "Jack" wrote: > How many times have you try to import the data into SQL table? Did you > delete all records in the table before you import the data if you did it > multiple times? > > "Jean-Francois" wrote: >
Post Follow-up to this messageDoes the total row returned from the "check duplicate" query match SELECT COUNT(*) FROM table? How do you import data from AS400 to SQL? Text file? DTS? "Jean-Francois" wrote: > I first delete the table and start over every time. > > "Jack" wrote: >
Post Follow-up to this messageI did an connection with client access driver to connect to the as400 and a query the as400 to retreive the data. "Jack" wrote: > Does the total row returned from the "check duplicate" query match SELECT > COUNT(*) FROM table? How do you import data from AS400 to SQL? Text file ? > DTS? > > "Jean-Francois" wrote: >
Post Follow-up to this message1> Bring the data over with primary defined in SQL table. 2> After the import, issue "ALTER TABLE table ADD id INT IDENTITY (1, 1). This will create a primary key for this table. 3> Use this command to delete duplicates: DELETE FROM table WHERE id NOT IN ( SELECT MAX(id) FROM table GROUP BY CustId, SubCustId) 4> Remove "id" column and set your primary key using CustId and SubCustId Then you would need to compare the data between SQL and AS400........... "Jean-Francois" wrote: > I did an connection with client access driver to connect to the as400 and a > query the as400 to retreive the data. > > "Jack" wrote: >
Post Follow-up to this messageAdd a Count(*) to the result set to see how many duplicates there are.. Then pick one and look to see whats up with the rows. SELECT CustId, SubCustId,Count(*) FROM table GROUP BY CustId, SubCustId HAVING COUNT(*) > 1 Bill "Jack" <Jack@discussions.microsoft.com> wrote in message news:8DE0E7B0-7EF9-472E-B8F7- CF53F4F1A25A@microso ft.com... > Is the primary key defined on both columns? If it is, try to import the > data > over without the primary key, then check for duplicates. > > SELECT CustId, SubCustId FROM table > GROUP BY CustId, SubCustId > HAVING COUNT(*) > 1 > > "Jean-Francois" wrote: >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread