How to drop primary key constraint from a column or table ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chandan Kr Sah
    New Member
    • Aug 2010
    • 11

    How to drop primary key constraint from a column or table ?

    How to drop primary key constraint from a column of table ?
    Actually I got so many example for this, but in that we require the primary key name also.
    But I dont have the primary key name.So if I execute the query like

    Code:
    select object_name (parent_obj) ObjectName, name from sysobjects where xtype = ‘PK’ and parent_obj = (object_id(‘Admin.Technologies’))
    its giving error as 'sysobject not found'
    So I think access have sysobject with different name.
    So please any body can help me in this scenario.
    Last edited by NeoPa; Sep 15 '10, 01:35 PM. Reason: Please use the [code] tags provided
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32655

    #2
    I suspect you would have noticed the problem yourself had you posted the code properly in the tags. The quotes are not proper quotes. They are special characters sometimes used in word processors. SQL only recognises proper quotes (').

    This often occurs when working in SQL in an editor that is really a word processor, so it is worth remembering only ever to use text editors (which have no automatic replacements in the setup).

    Comment

    • Chandan Kr Sah
      New Member
      • Aug 2010
      • 11

      #3
      Thanks for your reply...
      But after correcting the tags etc as below

      Code:
      select object_name(parent_obj), name from sysobjects where xtype='PK'
      I am getting the error message like:
      "The Microsoft Jet database engine cannot find the input table or query <name>. Make sure it exists and that its name is spelled correctly. (Error 3078)"
      Last edited by NeoPa; Sep 16 '10, 09:23 AM. Reason: Please use the [code] tags provided

      Comment

      • Chandan Kr Sah
        New Member
        • Aug 2010
        • 11

        #4
        I also tried like

        Code:
        select object_name(parent_obj), name from MSysObjects where xtype ='PK' and parent_obj=(object_id('Admin.Technologies'))
        but throwing error like
        "Undefined function <name> in expression. (Error 3085)"
        Last edited by NeoPa; Sep 16 '10, 09:24 AM. Reason: Please use the [code] tags provided

        Comment

        • Chandan Kr Sah
          New Member
          • Aug 2010
          • 11

          #5
          Drop Primary Key from a field VBA, Primary Key is unknown to me.

          Actually my intention is to drop Primary Key from a field,but the Primary Key constraint name is unknown to me.
          And whereever I got the script for that its uses Primary Key name with the query in VBA.

          so I need help in this scenario.

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            This is a bit of a longshot, as I've never worked directly with the system tables. However name is a reserved word as far as I know, and if you want to use it in a query, I think you need to enclose it in brackets like this:
            Code:
            select object_name(parent_obj), [name] from MSysObjects where xtype ='PK' and parent_obj=(object_id('Admin.Technologies'))

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32655

              #7
              I'm not sure how you can have access to the SQL Server yet not know the name of a particular PK. What version of the software is the server and what tool are you using to access it?

              PS. Please notice again that I've had to add code tags to your posts. I mentioned this before and you seem to understand (from your response) yet you're still not following the instruction. It's probably better if you do if you plan to keep using the site and you want your account to continue working.

              Comment

              Working...