Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MS SQL Server


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Duplication In The Primary Key Column


Hi
I have a set of excel files that i need to export to sql2005 using ssis. Now the issue is that i have no idea about he data ie it may have duplication in the primary key column. If i export it as it is to sql server, it will cause me problems. Is there any way i can filter out the rows which have duplication in the primary key column?
Umer




View Complete Forum Thread with Replies

Related Forum Messages:
Fix Legacy Data - Missing Primary Key + Duplication Record + Large Table
We have a large table which is very old and not much ppl take care about, recently there is a performance problem from the report need to query to this table. Eventally we find that this table have primary key missing and there is duplicate data which make "alter table add primary key" don't work

Besides the data size of this table require unacceptable time to execute something like "insert into new_table_with_pk from select distinct * from old table"

Do you have any recommendation of fixing this? As the application run on oracle , sybase and sql server, is that cross database approace will work?

View Replies !
Duplication
How can I achieve the following...
I have a Membership No. field which comes from a bookings table, so multiple membership no. do exist. What I want to achieve is a list of membership No.s with no duplication. Sorry to be so dumb, but we all have to start somewhere.

View Replies !
Differnce Between A Column That S A Primary Key And A Column That S A &&"key/index With Isunique=true&&"
 

Hi,
 
Please, What s the differnce between a column that s a primary key and a column that s a "key/index with Isunique=true"?
 
Thanks a lot.

View Replies !
Duplication Error
i have taple translatio witch have theses coloumn
ID,TypeID,Status,ComID,RecordID,Translator
in this table we assign  a certain company with a certain typeID  to a certain translator .
so next time when the translator log he goes to the company that he assigned to it when he log to the company page,
there is another company page n arabic that is transalted by the translators , in the arabic page there is a button when you can send this company to transaltion.
but a duplicate have been happen made because user send the same documnet to the translation table so many time so translator transalte the same company profile more than one time witch is not good.
 
we handle the duplicate of the send to translation button put still there is duplicate record in the database  witch is more taht 3000 record
how ican to remove thsi record from the DB without make ant other erroe
 
 

View Replies !
Report Job Duplication
 

HI
 
I have created a job to run a reporting services job which then named it in the job scheduler 354EEF12-404F-46BD-B54F-708B5027837F.  I then  renamed the job to Rpt ETL log.
 
However it I was surpised to see two emails come with reference to this report.   It seems to have created another one with the long job names.
 
Is there any way to stop this as I would really like to name to schduled rpt jobs without it duplicating.
 
 
Many Thanks
 
Robert

View Replies !
Get Primary Key Column
Hello, this SQL query gets all columns of a table:

SELECT syscolumns.name AS [Fields in Items Database], syscolumns.type,
syscolumns.length, syscolumns.isnullable FROM sysobjects INNER JOIN
syscolumns ON sysobjects.id = syscolumns.id WHERE sysobjects.name =
'IssueTracker_IssueAttachments' ORDER BY syscolumns.colid

I would like to know, is there a way to get a column saying who is the
primary key in the table ? I am reading columns for tables and
processing them, but I would like to know who is the primary key, is
that possible ?

regards

View Replies !
Prevent Duplication On UPDATE
Hello
I noticed a spelling mistake in the data in a column of several tables, I used the following syntax to alter the spelling:
UPDATE [dbo].[Prod_Cat]     SET  [ProdName]=N'merseyside'    WHERE ProdName = 'mmserseyside'
The above code correctly updated the spelling error, but it also inserted a new row with the corrected data. 
So I found myself with two Identical rows containing the corrected information. I had to manually delete the extra row. Because if I had put in a DELETE statement, I would have then lost both rows.
What do I need to do to prevent this happening next time.  As I find that I need to update the names of some products, but I don't want to duplicate them.
Thanks
Lynn

View Replies !
Track Duplication Of Records
Hello,

I have a table which consists of 27,000 of records. Among these records, there is one record which
is a duplication of another record.

Is there any way to track this record from the same table by the SQL statement ?

I have been advised to use the following statement but it does not help:

Select count(*) As Duplicate, columnname from tablename group by columnname

Scrolling 27,000 lines of records with bare eyes is very painful.

Any help is appreciated.


Cheers

View Replies !
De-Duplication Performance Issue
Hi All,
 
 
Scenario: De-duplication logic should pick one record from source and check with all the destination records and insert if not duplicate. Else raise error. There are average 8 to 10 lookup check for each logic path. Key fields used for de-duplication check are FirstName, LastName, DOB, Gender, SSN.
 
Issues:
·         Since picking row by row and processing the performance is constrained.
·         Since 8-10 comparison is done using lookup performance downstream. (Lookup is used without caching, if cashing is used the package is failing after sometimes as if memory is failing. Can we handle this memory problem?)
 
Please give some suggestion to improve the performance. Current performance is around 2500 records per hour, but there are 8 lac records in total to process.
 
 
I am looking for guidance on this issue. If someone can guide me on how to do it better it would help me a lot.
 
Thanks,
S Suresh
 

View Replies !
How To Avoid PrimaryKey Duplication?
Hi, I having a problem with my query...

I want to copy data from 4 different database to 1 database... but if the destination database have already the same Primary Key the copying stops/terminated and not copying others that is not yet in the destination...

I don't have knowledge in T-SQL like IF...ELSE
my database is SQL Server 2000 but i'm using SQL 2005 Express Management for the query...

What i'm doing is like this:

Use osa (Destination Database)
Go

DELETE FROM tblFaculty (*I'll delete first the datas to avoid duplication)

INSERT INTO tblFaculty (FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode)
(SELECT FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode FROM cislucena.dbo.tMasFaculty)

INSERT INTO tblFaculty (FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode)
(SELECT FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode FROM amapn.dbo.tMasFaculty)

INSERT INTO tblFaculty (FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode)
(SELECT FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode FROM abe.dbo.tMasFaculty)

INSERT INTO tblFaculty (FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode)
(SELECT FacultyID, LastName, FirstName, MiddleName, Rank, DeptCode FROM aclc.dbo.tMasFaculty)

My problem is if the facultyID (PrimaryKey) which i'm copying is already on the destination which is osa, the copying stops/terminated regardless whether there is more to copy. On the 4 source database, there might data that other database also has. That's why the copying is terminated. All i want to do is to check first each FacultyID if it is already on the destination before copying it to avoid error or duplication of Primary Key so it won't terminate the copying.

How is this possible sir? Anyone care to help? Thanks in advance! More Power!

Best Regards

View Replies !
SQL Set Primary Key On Existing Column
Hi everyone,How do I set a primary key on an existing column using SQL statements? I have column persID of type int in table employees. How do I correctly apply the ALTER command to change persID type to INT IDENTITY(1,1) NOT NULL?  Thanks in advance   

View Replies !
How To Drop Primary Key By Specifying Column Only?
I checked column from xsd file which created from DataBase.
And before installing my application I will check any column in destination base whether have complete column or not.
 
And if there is any column which is not wanted column(not same as xsd structure)
I will delete it by creating sql command as follow "ALTER TABLE tableName DROP COLUMN column1, column2, ......"
and Execute it by program initialization.
 
So
I need delete it by run-time
 
 
However some column may be Primary Key with any reason
 
That's why I can't delete them by simple command
 
I expect to delete them by specific column instead of specific constraint name which is not sure name.
 
 
Please advise me....

View Replies !
Primary Key Vs Identity Column
What is the different between Primary key and Identity Column? and when should I them?
(Im just a beginner with databases...)

View Replies !
Column Name In A Primary Key Constraint
Hi allWould there be a easy way to find the column name(s) which constitutea Primary constraint for a table through navigating the systemcatalogs.I found that the PK Constraint object in syscontraints is showing thecolid = 0.TIANorman

View Replies !
Primary Key VS Identity Column
Can anyone explain the Difference between Primary Key and Identity Column in MSSQL Server 6.5. Please give me any example if possible.
Thanks for Help!!!!

View Replies !
Replication When I Have Primary Column
Hi ,

        I have problem with replication of the DB from SQL Server 2005 to SQL Express, I am using the Merge replication, I am having set of master tables (with primary key) which are residing at the subscriber(SQL Express) and publisher(SQL Server 2005) and after publishing these tables, when I subscribe to the publication, merge agent  tries to syncronize the published tables with the tables at the SQL Express end (which is subscriber in this case), the merge agent is throwing error as shown below:

 

Command Attempted:

{call sp_MSsetconflicttable (N'MstrApplication', N'MSmerge_conflict_TestingOnceMore_MstrApplication', N'NGAURSQLSERVER2005', N'NewDBForReplTest', N'TestingOnceMore')}


Incorrect syntax near 'ApplicationCode'. (Source: MSSQLServer, Error number: 102)

 

Here we are using the system stored procedure "sp_MSsetconflicttable" which will be called implicitely for replication. Could any one of you tell what's the problem?

 

Thanks in advance,

 

Regards,

Hemanth.

 

 

View Replies !
Determin Name Of Primary Column
given the name of any table how can i programmatically get the name of the primary key column?

View Replies !
How To Knw Which Column Is Primary Key In A Table
hi all

my question is which query shud i use in sql server 2000 to get which column or columns are primary keys of table

i dont want to use any stored procedures only sql query

sp_primary_keys_rowset is one of d stored proc in sql server 2005 but i couldn't understand which query they are using

i only want to use sql query

View Replies !
Select Primary Key Column
Is there a query that can return teh name of the primary key column of a table ?

View Replies !
Single Field Duplication Problem
I have a table with many fields but there is a single field that I do not want duplicates. If I index this specific field preventing duplicates, the entire record does not append. (The field in question is not keyed).


Thanks

Bill Howard

View Replies !
Designating An Identity Column When You Already Have Primary Key
Hello --
Following normal practice, I have an autoincrementing identity column designated as primary key in my table.  I have two other columns that should also contain unique values per record, but the Identity option is greyed out (in Management Studio) for all columns other than the primary key.
 I'm enforcing this programmatically (in my C# code) at this point, but I'd like to back that up with a constraint in the database itself.
Any help is appreciated.
Eric

View Replies !
Getting Primary Key Column Names For All Tables
I have a situation in which i have to get the last value stored in the Primary Key for all the tables. Based on this value i have to update another table which stores the Table names and the last Key value for the table. The values in this table are not correct therefore i have to update it now. I was trying to write a cursor for this but the only problem is i can't get to know how to get the column name on which the primary key is defined for all the tables, thru code.

I would appreciate if someone could help me out with this.

View Replies !
Identity Column Primary Key Vs Custom Key
We are developing a batabase which is meant for financial domain,so it will import data from different source system..
and data from our data base will be further passed to other applications.

In contex of our system integration with other data sources ,whether  is it a good idea to have a auto integer primary key a or  to implement  some  logic  to generate primary key?

Can some one guide us to some pratical data base design case studies?or some best practices.?

View Replies !
Creating Primary Key On Nullable Column
Hello,

I am trying to recreate a primary key that I dropped in a table....

I'm using a statement like

ALTER TABLE temp WITH NOCHECK add CONSTRAINT PK__tempkey PRIMARY KEY CLUSTERED

(

num,
store
)


But apparently the "store" column was created without a "not null" and it let it create the PK during the table creation but now it won't let me add the PK with that nullable column..

Does anyone know how to get it to use that column to create a primary key after the initial table creation?

Here is the error i get

Cannot define PRIMARY KEY constraint on nullable column in table


Thanks a lot

View Replies !
Problems With Computing A Primary Key Column
hi !

Just started playing around with SQL 2000 and I createda sample table called 'actor' which has 4 columns

1. actorID
(formula= LEFT(NEWID(), 3)+ LEFT([actorFirst], 2) +
LEFT([actorLast], 2) + RIGHT(NEWID(), 3))
2. actorFirst
varchar(20) NOT NULL
3. actorLast
varchar(20) NOT NULL
4. actorName
(formula = [actorFirst] + ' ' + [actorLast]

Now my problem is that I want to set a primary key constraint on actorID but it doesn't let me because it the NULL check mark is automatically checked and I cannot check it off ... and I can't set a primary key on something which is allowed to be NULL....

I don't understand why 'actorName' column which is also calculated doesn't have that default NULL checked and locked ....

What am I doing wrong ? Please help ....

View Replies !
Error Catching On Data Duplication In A Sql2005 Db
Hello, everyone.  I am having problems catching a data duplication issue.  I hope I can get an answer in this forum.  If not, I would appreciate it if someone can direct me to the right forum.
I am working on a vs2005 app which is connected to a sql2005 db.  Precisely, I am working on a registration form.  Users go to the registration page, enter the data, ie. name, address, email, etc. and submit to register to the site.
The INSERT query works like a charm.  The only problem is that I am trying to reject registrations for which an email address was used.  I put a constraint on the email field in the table and now if I try to register using an e-mail address that already exists in the database I get a violation error (only visible on the local machine) on the sql's email field, which is expected.
How can I catch that there is already an email address in the database and stop the execution of the code and possibly show a message to the user to use a different address?
 Thank you for all your help.
 
Antonio

View Replies !
Unsorted Primary Key Column In SQL Server Database
Update: Changed original post as I figured it was not the problem I stated. 
Hi all,
Heres the problem. I have a table in SQL Server with two fields, PartSubCategory and PartCatID. PartSubCategory is the primary key. When I import an excel sheet with identical columns into this table, the primary key column in the table gets sorted automatically (alphabetically). I don't want this column  sorted but to import the rows from excel in the order as they were. Is this some indexing issue? Is there a fix?
Thanks a lot...Bullpit

View Replies !
Creating A New Numbered Column As Primary Key In A Table
This is a fairly simple question, but what is the easiest way to:create a new numbered column (where value is simply the row number) inan existing table and setting it as a primary key?

View Replies !
How To Find All Tables That Have An Identity Column As A Primary Key
 How do i find all the tables that have an Identity Column as a primary key in a database. Thanks.

View Replies !
Multi Column Primary Key's In Access Using ADOX [c#]
Hi all,

I have been pulling my hair trying to figure out what the guys at microsoft were thinking when creating the ADOX library. I have an access table that is syncronized with a SQL server. The table has a primary key with two columns [User] and [Program]. The SQL Server has both columns in as the primary key columns and I have a syncronization mechanism that is responsible for several things, one of which is to recreate the Access data structure. All works well for all tables except this one. I have tried to create the multi-column key in several ways, none that worked. Let me show you what I am doing:
 
 

CatalogClass catDCDLocal;

Column c;

catDCDLocal = new CatalogClass();

catDCDLocal.let_ActiveConnection(dbAccess.buildConnectionString(Settings.CattDCDLocalPath, Settings.SecurityDBPath, s.UserID, s.Password));

 
foreach (Table tbl in catDCDLocal.Tables) {  
   if (tbl.Name == "Users") {     


/* This is retarded so need to clean up... Users table has a primary key consisting of 2 columns */

for (int i = tbl.Keys.Count - 1; i >= 0; i--) { //remove the keys

tbl.Keys.Delete(i);

}

for (int i = tbl.Indexes.Count - 1; i >= 0; i--) {  //remove the indexes

tbl.Indexes.Delete(i);

}

tbl.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyUnique, "User", "", "");
tbl.Keys[0].Columns.Append("Program", DataTypeEnum.adWChar, 6);

   }
}
 
I have also tried:

tbl.Keys.Append("PrimaryKey", KeyTypeEnum.adKeyUnique, "User", "", "");

//tbl.Keys[0].Columns.Append("Program", DataTypeEnum.adWChar, 6);

Key k = tbl.Keys[0];

Column col = tbl.Columns["Program"];

//col.ParentCatalog = catDCDLocal;

k.Columns.Append(col, DataTypeEnum.adWChar, 6);
 
 
 
Nothing works for me ;-(
 

View Replies !
Partitioning Table Based On A Non Primary Key Column
We are facing few issues pertaining to creation of primary key on a non - partitioned column in sql server 2005. Herewith attaching the text file containing the detailed scenario.
 
Pls advice.

 
Pls find some of the scenario with the example given below:
 
We have done the following steps
1.Creating a Partition Function
CREATE PARTITION FUNCTION pf_EncounterODS_StateID (CHAR(2))
AS RANGE RIGHT FOR VALUES
(
    'CA',      -- CA
    'MI',      -- MI
    'NM',      -- NM
    'OH',      -- OH
    'TX',      -- TX
    'UT',      -- UT
    'WA'       -- WA
)
GO
2.Creating a Partition Schema
CREATE PARTITION SCHEME [ps_EncounterODS_StateID]
AS PARTITION pf_EncounterODS_StateID TO
(
    [PRIMARY],
    [ENC_DM_DATA_01],   -- CA
    [ENC_DM_DATA_03],   -- MI
    [ENC_DM_DATA_04],   -- NM
    [ENC_DM_DATA_05],   -- OH
    [ENC_DM_DATA_06],   -- TX
    [ENC_DM_DATA_07],   -- UT
    [ENC_DM_DATA_02]    -- WA
)
GO

3.Creating a table using above partitioned schema

CREATE TABLE [dbo].[Fact] (
 [ValidationErrorSID] [bigint] NOT NULL IDENTITY(1,1),
 [ProcessID] [int]  NULL ,
 [StateID] [char] (2)  NOT NULL ,
 [ClaimID] [char] (15)   NULL ,
  
) ON [ps_EncounterODS_StateID](StateID)

4.Creating a primary key on validationErrorSID column in the fact table
ALTER TABLE [Fact] ADD CONSTRAINT NQValidationError PRIMARY KEY CLUSTERED ([ValidationErrorSID])
Step 4 throws an error as
---------------------------------
Column 'StateID' is partitioning column of the index 'NQValidationError'. Partition columns for a unique index must be a subset of the index key.
If we include StateID along with ValidationErrorSID for index,then it works fine.But we need to have only ([ValidationErrorSID]) for indexing.

View Replies !
Inserting Into SQL 7.0 With An Identity Column As The Primary Key Problems
Hi I'm using Visual Web Developer Express 2005 and I'm connecting to a SQL 7.0 database.  The table I'm connecting to is a table where I store help desk issues that I've encountered.  Since I could have tons of help desk issues with multiple instances of the same user, same issue I decided to go with a column called "ID" as the primary key, I was also thinking of using an automatic time stamp but I'd rather use the "autonumber".  "ID"s property is set to Identity.  To select,update,insert and delete I just use the automatic generate statements VWD makes for you.  Select, Delete and update work fine but the insert gives me this error.
ERROR [23000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot
insert explicit value for identity column in table 'HelpDesk'
when IDENTITY_INSERT is set to OFF. Even though it says I'm inserting something into the identity column I am not.  That box isn't available when I'm inserting a new HelpDesk issue.
I've tried many things I've seen on forums such as:  putting the Identity_insert ON statement in my insert statement, not putting the "ID" column in the insert statement(which works but then it will insert the data into the wrong columns).  Here is the insert statement generated by VWD

INSERT INTO [HelpDesk] ([ID], [Username], [Issue], [Resolution]) VALUES (?, ?, ?, ?)

oh, also I don't think I want to use a GUID because that seems like it will be to large for what I'm doing.
Any suggestions would be appreciated

View Replies !
Creating A Primary Key Column In SQL Server 2005
I have a varchar column in a table, which is an unique key column. Now when I design this table should I use this column as a primary key or should I add one more Integer column as a primary key column for the performance?

One more point is, when ever I do a search on this table I will search based on that unique varchar column values only, so even then if I add new integer column just for Primary key I will not use this column for searching values.

With these information, can some body help me in deciding this?

View Replies !
Insert Statement Results In Data Duplication Using MDAC 2.8
I am using Remote Data service to Query an Sql Server Database using MDAC. The Os in which server is loaded in Window 2003 and the MDAC 2.8 version is installed. Now I create a table X with identity column. Then when I try to insert records in that table using Insert into X select * from Y statement. The statement gets executed by when i check the X table I find that the duplicate records are present with different identity no's.

Even when i truncate and retry the same thing occurs.

What could be the reason for the same??

Regards
Pranali.cons

View Replies !
Slowly Changing Dimension Wizard Doesn't Display Destination Table Primary Key Column
I have added a Slowly Changing Dimension transformation to an SSIS package and have launched the Wizard to edit it.  After selecting the source (a SQL Server 2005 instance), if I select a very large table (9+ million rows), I'm encountering two strange behaviors:
1. The wizard hangs for several minutes before displaying the columns from that table.
2. The wizard does not display the primary key column.  This, of course, is the column I want to designate as the "business key", but can't because it's not displayed.
I know this is more like a fact table than a dimension, but this is not a data warehouse.  This is just a very large table, and I need to update a field in certain records based on the contents of a source text file.  Is there another transformation I should use to perform updates?

View Replies !
Createing Column Primary Key And Contains Of 3 Characters And 6 Auto Increment Numbers (example: &&"DLL - 123456&&") (
i would to make a column contains of  3 characters and 6 auto increment numbers (example: "DLL -  123456")

and made it primary key and which data type i should use. i do not know whether i use after insert trigger in two columns one for three characters and another for code which has identity property >>>so please help me

View Replies !
&"Ghost&" Primary Key Column
Hello,I have a table 'customers', with 2 records:SELECT * FROM customers;customerID | customerName------------------+-------------------------myFriend | myFriend's Nametest | testing user(2 rows)but when I'm asking about customerID column, I get the answer:SELECT customerID FROM customers;ERROR: column "customerid" does not existWhat happens? I'm using PostgreSQL 8.1.3

View Replies !
Convert Composite Primary Key Into Simple Primary Key
Uma writes "Hi Dear,
I have A Table , Which Primary key consists of 6 columns.
total Number of Columns in the table are 16. Now i Want to Convert my Composite Primary key into simple primary key.there are already 2200 records in the table and no referential integrity (foriegn key ) exist.

may i convert Composite Primary key into simple primary key in thr table like this.



Thanks,
Uma"

View Replies !
Stuck Between &"Cannot Insert The Value NULL Into Column 'ID'&" And &"Violation Of PRIMARY KEY Constraint&"
Cannot find an answer to this in previous posting, though there are similar topics.

My primary key "ID" requires a value (is not nullable), and not explictly providing it with one when I update a new record gives the following error:

Cannot insert the value NULL into column 'ID', table 'AdClub.mediaq.News'; column does not allow nulls. INSERT fails.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'ID', table 'AdClub.mediaq.News'; column does not allow nulls. INSERT fails.

However, trying to stuff that field with a recordCount+1 value (or any value), I get this error:

Violation of PRIMARY KEY constraint 'Primary Key'. Cannot insert duplicate key in object 'News'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'Primary Key'. Cannot insert duplicate key in object 'News'.

Cannot figure this one out. The value I'm providing for that field is known to be unique, but the SQL Server spits it out each time.

Is there a way to have the ID primary field automatically update with a new value when a new record is generated? This is how I used to do it in Access, but cannot find a similar feature in SQL Server. I'm sure I'm missing something simple, but right now I'm stuck in this "Catch-22" situation.

Please help!

View Replies !
Adding Primary Key To A Table Which Has Already A Primary Key
Hi all,
Can anyone suggest me on Adding primary key to a table which has already a primary key.

Thanks,
Jeyam

View Replies !
Auto Incremented Integer Primary Keys Vs Varchar Primary Keys
Hi,

I have recently been looking at a database and wondered if anyone can tell me what the advantages are supporting a unique collumn, which can essentially be seen as the primary key, with an identity seed integer primary key.

For example:

id [unique integer auto incremented primary key - not null],
ClientCode [unique index varchar - not null],
name [varchar null],
surname [varchar null]

isn't it just better to use ClientCode as the primary key straight of because when one references the above table, it can be done easier with the ClientCode since you dont have to do a lookup on the ClientCode everytime.

Regards
Mike

View Replies !
4 Key Primary Key Vs 1 Key 'artificial' Primary Key
Hi all

I have the following table

CREATE TABLE [dbo].[property_instance] (
[property_instance_id] [int] IDENTITY (1, 1) NOT NULL ,
[application_id] [int] NOT NULL ,
[owner_id] [nvarchar] (100) NOT NULL ,
[property_id] [int] NOT NULL ,
[owner_type_id] [int] NOT NULL ,
[property_value] [ntext] NOT NULL ,
[date_created] [datetime] NOT NULL ,
[date_modified] [datetime] NULL
)

I have created an 'artificial' primary key, property_instance_id. The 'true' primary key is application_id, owner_id, property_id and owner_type_id

In this specific instance
- property_instance_id will never be a foreign key into another table
- queries will generally use application_id, owner_id, property_id and owner_type_id in the WHERE clause when searching for a particular row
- Once inserted, none of the application_id, owner_id, property_id or owner_type_id columns will ever be modified

I generally like to create artificial primary keys whenever the primary key would otherwise consist of more than 2 columns.

What do people think the advantages and disadvantages of each technique are? Do you recommend I go with the existing model, or should I remove the artificial primary key column and just go with a 4 column primary key for this table?

Thanks Matt

View Replies !
How To Refer A Column When The Referencing Column Is An Identity Column
Hi all,

The requirement is to have a table say 'child_table', with an Identity column to refer another column from a table say 'Parent_table'..

i cannot implement this constraint, it throws the error when i execute the below Alter query,

ALTER TABLE child_table ADD CONSTRAINT fk_1_ct FOREIGN KEY (child_id)
REFERENCES parent_table (parent_id) ON DELETE CASCADE

the error thrown is :
Failed to execute alter table query: 'ALTER TABLE child_table ADD CONSTRAINT
fk_1_ct FOREIGN KEY (child_id) REFERENCES parent_table (parent_id) ON DELETE
CASCADE '. Message: java.sql.SQLException: Cascading foreign key 'fk_1_ct' cannot be
created where the referencing column 'child_table.child_id' is an identity column.

any workarounds for this ?

View Replies !
TSQL - Using ALTER TABLE - ALTER COLUMN To Modify Column Type / Set Identity Column
Hi guys,
If I have a temporary table called #CTE
With the columns
[Account]
[Name]
[RowID Table Level]
[RowID Data Level]
and I need to change the column type for the columns:
[RowID Table Level]
[RowID Data Level]
to integer, and set the column [RowID Table Level] as Identity (index) starting from 1, incrementing 1 each time.
What will be the right syntax using SQL SERVER 2000?
 
I am trying to solve the question in the link below:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2093921&SiteID=1
 
Thanks in advance,
Aldo.
 
I have tried the code below, but getting syntax error...


 
ALTER TABLE #CTE
ALTER COLUMN
[RowID Table Level] INT IDENTITY(1,1),
[RowID Data Level] INT;
 
 
I have also tried:

ALTER TABLE #CTE
MODIFY
[RowID Table Level] INT IDENTITY(1,1),
[RowID Data Level] INT;
 



 


 

View Replies !
Alter Table Add Column - How Do You Add A Column After Say The Second Column
 

When you use  "Alter Table add Column",  it adds the column to the end of the list of fields.

 

How do you insert the new column to position number 2 for instance given that you may have more than 2 columns?

 

Create table T1 ( a varchar(20), b varchar(20), c varchar(20))

 

Alter table add column  x    varchar(20)  

so that  the resulting table is

T1 a varchar(20), x varchar(20), b varchar(20), c varchar(20)

 

Can this be done programmatically?

 

 

 

 

 

 

 

View Replies !
ALTER TABLE DROP COLUMN LastUpdated Failed Because One Or More Objects Access This Column.
Hi I’m trying to alter a table and delete a column I get the following error. The object 'DF__Morningst__LastU__19EB91BA' is dependent on column 'LastUpdated'.
ALTER TABLE DROP COLUMN LastUpdated failed because one or more objects access this column. I tried deleting the concerned constraint. But the next time I get the same error with a different constraint name. I want to find out if I can dynamically check the constraint name and delete it and then drop the column. Can anyone help.IF EXISTS(SELECT 1FROM sysobjects,syscolumnsWHERE sysobjects.id = syscolumns.idAND sysobjects.name = TablenameAND syscolumns.name = column name)BEGIN EXECUTE ('ALTER TABLE tablename DROP CONSTRAINT DF__SecurityM__DsegL__08C105B8')EXECUTE ('ALTER TABLE tablenameDrop column columnname)ENDGO
 

View Replies !
Cast/Convert Mmddyy In String To New DB_DATETIMESTAMP Column In Derived Column Transformation
Hi,
I have dates in "mmddyy" format coming from the sources and they are older dates of mid 80s like 082580 for instance.

When I cast it this way (DT_DBTIMESTAMP) Source_Date , It says ok but throws a runtime error.

When I hardcode a date in same format, (DT_DBTIMESTAMP) "082580" , It becomes red (an indication of syntax error) . Please note that we use double quotes in expressions in Derived Column Transformation; So an anticipation that using double quotes over single ones would be the syntax problem would be wrong.



Any help in this will sincerely be appreciated.


Thanks

View Replies !
Matrix Sub Total Column Width And Multiple Subtotals At Same Column Group Level
All,
 
I have two questions. First how can I make the width of the subtotal column in a matrix bigger than the column group cells. Secondly, how can I display two subtotals at the same group level, say one that adds all the columns and one that provides the product of subtotal and some value X?
 
Thanks.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved