Results 1 to 6 of 6

Thread: problem in primary keys

  1. #1
    Join Date
    Aug 2009
    Posts
    57

    problem in primary keys

    Hello to all,
    I am new to this forum. I recently started learning SQL language. I have create one table in which there are three columns namely ids, tags1, tags2. In this ids is a primary key. In that I want one unique tags1-tags2-combination. So I have made three columns primary keys but the problem is that the second entry is inserted in another column. I don't know what is the problem in primary keys. Please help me to fix this problem.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: problem in primary keys

    It seems that you are tried to add same data in two different table and you are tried to assign different primary key for these two table and that's why you are getting such type of problem. In this case you have to merge two table in one table to fix this problem. For Eg. Make table like as follows:
    IDs
    tags1: cat
    tags2: mouse
    tags3: dog

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: problem in primary keys

    As per my knowledge you have to leave IDs as the primary key and after you have to create a unique constraint for the tags1 and tags2 to fix this problem. You have to use following code in your program to fix this problem.

    Code:
    ALTER TABLE mys_table ADD CONSTRAINT ucs_tags UNIQUE (tags1, tags2)
    In the above code I ave use unique constraint to avoid two rows with duplicate tags1 and tags2 values.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: problem in primary keys

    You have to use UNIQUE constraint in your code to fix this problem. It is very easy to use. This technique uniquely identifies each record in a database table. The UNIQUE and PRIMARY KEY constraints provides uniqueness for a column. Fro better understanding look at below example.
    Code:
    CREATE TABLE Personss
    (
    Ps_Ids int NOT NULL,
    LastNames varchar(268) NOT NULL,
    FirstNames varchar(232),
    Addresss varchar(269),
    Citys varchar(236),
    UNIQUE (P_Ids)
    )

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: problem in primary keys

    You have to add unique index that combines tags1 and tags2. You also have to use CREATE INDEX to fix this problem. CREATE INDEX is used to mapped to an ALTER TABLE statement to create indexes. It is very easy to implement and use. I have written syntax of this. Just try to use it in your code.

    Code:
    CREATE [ONLINEs|OFFLINEs] [UNIQUEs|FULLTEXTs|SPATIALs] INDEX index_name
        [indexs_types]
        ON tabls_name (indexs_cols_names,...)
        [indexs_options] ...
    
    indexs_cols_names:
        cols_names [(length)] [ASC | DESC]

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: problem in primary keys

    You have to create TempWork table with same structure as the final destination table. It is very simple one. You also have to use "unique record" to fix this problem. You also have to use "id" to fix this problem. You also have to use primary key for tags1 and tags2. It is very simple code. Just try to understand it.

Similar Threads

  1. Problem of arrow keys with VMWARE
    By D_chapple in forum Windows Software
    Replies: 5
    Last Post: 23-12-2009, 11:39 AM
  2. Circumflex keys problem
    By JUSTICE in forum Windows Software
    Replies: 3
    Last Post: 27-04-2009, 07:02 PM
  3. Keysonic ACK-540 Mac Keys problem!
    By RoadRunner in forum Hardware Peripherals
    Replies: 2
    Last Post: 23-04-2009, 09:40 AM
  4. Problem keyboard keys F1 F2 F3 F..
    By Daryl in forum Hardware Peripherals
    Replies: 2
    Last Post: 19-12-2008, 06:33 PM
  5. Replies: 2
    Last Post: 03-06-2008, 03:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,278,801.60600 seconds with 17 queries