Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Posts
    47

    Question Unanswered: Search By Primary Key

    Hi I want to know how can I search for a particular record in a table by Primary Key (Indexing)
    I mean I have a table with 1000 records and I want a particular row if I start searching I m sure it would start with table scanning...Is there way with with I can reduce the serach time by going to tht particular record using Indexing or something?

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    if the table has a pk and you use the pk in the where clause, the query plan should come up with a seek, not a scan.

  3. #3
    Join Date
    Mar 2009
    Posts
    47
    R u sure with this no table sacn wud be ther?

  4. #4
    Join Date
    Mar 2009
    Posts
    47
    Is it possible to find a row W/O where clause with the use of PK

  5. #5
    Join Date
    Dec 2008
    Posts
    135
    is this u want
    select name,object_name(parent_object_id)as tablename from sys.objects where type ='pk'

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Most RDBMSs (including SQL Server) use indexes to enforce the logical UNIQUE and PRIMARY KEY constraints. So by definition, if you have defined a Primary Key, it will be indexed. Now it is possible that the table will be scanned rather than use the primary key index - there are a few reasons for this, but the vast majority of the time it will use the PK index in a seek operation.

    Why don't you run the query with the graphical execution plan on? If it scans the table, post your query.
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •