Results 1 to 5 of 5

Thread: Defining primary key on database table

  1. #1
    Join Date
    Jan 2010
    Posts
    53

    Defining primary key on database table

    I have a large table and there is no any restriction to insert the value and I want to make a field as a unique. The data which would be entered into that particular column,That should be uniquely identified for that tuple. So the primary key concept comes into my mind but how would I implement after creation of table. So please go through the procedure to make a field Unique for whole table data.

    Thanks...

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Defining primary key on database table

    Defining primary key :

    The is the combination of one or more field which uniquely identify particular tuple of a table.A table can have only one primary key.The primary key can be defined for a table before and after creation of table.

    The creation of primary key constraint for a table during creation of table would be as follows :

    Code:
    CREATE TABLE table_name
    (col1 datatype null/not null, col2 datatype null/not null,...
    CONSTRAINT constraint_name PRIMARY KEY (col1, col2, . col_n));
    In this way,you can define the primary key for a table during creation of table.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Defining primary key with ALTER command

    Defining primary key after table creation :

    You can create the primary key constraint after creation of table.The primary key can be defined using ALTER ... command of the database.

    The definition of primary key would be as follows:

    Code:
    ALTER TABLE table_name
    add CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n);
    The add CONSTRAINT option will create the primary key using ALTER TABLE statement.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Dropping primary key of database table

    Dropping primary key :

    You can define the primary key and drop it also using drop statement.You can create the primary key manually and automatic. The default primary key is automatically created when you define any column as UNIQUE.

    In the case of UNIQUE,you can alter the primary constraint but can't delete and you can edit it. If you have created manually then you define that with a name.Use that name to DROP the primary key which is given below :

    Code:
    ALTER TABLE table_name
    drop CONSTRAINT constraint_name;

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Disabling and Enabling primary key

    Disabling and Enabling primary key :

    You can disable and enable the functioning of primary key constraint of your database table.Here I am going to show you the syntax to disable and enable it.

    To Disable,use this statement :

    ALTER TABLE table_name
    disable CONSTRAINT constraint_name;
    To Enable,use this statement :

    ALTER TABLE table_name
    enable CONSTRAINT constraint_name;

Similar Threads

  1. Defining and controlling database in SQL
    By GOOL in forum Software Development
    Replies: 5
    Last Post: 25-12-2010, 08:42 AM
  2. How to list all table containing SQlite database
    By Neil'o in forum Software Development
    Replies: 4
    Last Post: 24-02-2010, 11:00 PM
  3. Increasing primary key values in database
    By Aileen_L in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 04:28 PM
  4. Scan a directory or table in database
    By KADIN in forum Software Development
    Replies: 4
    Last Post: 03-11-2009, 07:03 PM
  5. Check if database or table exists
    By Xan in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 04:53 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,727,327,758.14640 seconds with 16 queries