Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:08:10+00:00 2026-06-05T07:08:10+00:00

Can anyone explain about the purpose of PRIMARY KEY , UNIQUE KEY and KEY

  • 0

Can anyone explain about the purpose of PRIMARY KEY, UNIQUE KEY and KEY, if it is put together in a single CREATE TABLE statement in MySQL?

CREATE TABLE IF NOT EXISTS `tmp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` varchar(255) NOT NULL,
  `name` varchar(255) NOT NULL,
  `tag` int(1) NOT NULL DEFAULT '0',
  `description` varchar(255),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uid` (`uid`),
  KEY `name` (`name`),
  KEY `tag` (`tag`)
) ENGINE=InnoDB AUTO_INCREMENT=1 ;

How do I convert this query to MSSQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:08:11+00:00Added an answer on June 5, 2026 at 7:08 am

    A key is just a normal index. A way over simplification is to think of it like a card catalog at a library. It points MySQL in the right direction.

    A unique key is also used for improved searching speed, but it has the constraint that there can be no duplicated items (there are no two x and y where x is not y and x == y).

    The manual explains it as follows:

    A UNIQUE index creates a constraint such that all values in the index
    must be distinct. An error occurs if you try to add a new row with a
    key value that matches an existing row. This constraint does not apply
    to NULL values except for the BDB storage engine. For other engines, a
    UNIQUE index permits multiple NULL values for columns that can contain
    NULL. If you specify a prefix value for a column in a UNIQUE index,
    the column values must be unique within the prefix.

    A primary key is a ‘special’ unique key. It basically is a unique key, except that it’s used to identify something.

    The manual explains how indexes are used in general: here.

    In MSSQL, the concepts are similar. There are indexes, unique constraints and primary keys.

    Untested, but I believe the MSSQL equivalent is:

    CREATE TABLE tmp (
      id int NOT NULL PRIMARY KEY IDENTITY,
      uid varchar(255) NOT NULL CONSTRAINT uid_unique UNIQUE,
      name varchar(255) NOT NULL,
      tag int NOT NULL DEFAULT 0,
      description varchar(255),
    );
    
    CREATE INDEX idx_name ON tmp (name);
    CREATE INDEX idx_tag ON tmp (tag);
    

    Edit: the code above is tested to be correct; however, I suspect that there’s a much better syntax for doing it. Been a while since I’ve used SQL server, and apparently I’ve forgotten quite a bit :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please explain me about carp subroutine with sample Perl code?
Can anyone explain insights about the difference between Stack corruption and Static corruption ?
Can anyone explain what the jquery documentation is exactly referring to with this statement:
Can anyone explain me about gestures? What are their use? Can u tell me
I found about this PHP Extension before few days. Can anyone explain me how
Can anyone explain to me how to create a variable (in c), assign a
Im very new to Oracle so can anyone please explain about sys and system
I know it is about the dangers of cross-site scripting. But can anyone explain
Can anyone explain about delegate methods in TwitPic API and tell me the architecture
What does the view scope mean? Can anyone explain about it, so that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.