SQL Server BasicsWhat is SQL Server database?What is RDBMS?What is Normalization?Why we use Denormalization?What_is_SQL?What is PL/SQL?Difference between SQL and PL/SQLDatabase TableOne to One RelationshipOne to Many RelationshipMany to Many RelationshipMany to One RelationshipString Data TypesNumber Data TypesDate Data TypesOther Data TypesCreate DatabaseDrop DatabaseCreating and Managing Users in SQL ServerCreate TableAlter TableDrop TableConstraints in SQL serverPrimary KeyForeign KeyUnique KeyCandidate KeyComposite KeyDifference between primary key and candidate keyPrimary key and foreign key relationshipSurrogate KeyCascading Referential Integrity ConstraintsSelf Referential Integrity ConstraintsInsert into statementInsert multiple recordsUpdate statementDelete statementTruncate statementDifference between Delete and TruncateAlias in SQL ServerSelect statementSelect DistinctSelect TopSelect IntoNull Functions(ISNULL(),NULLIF(),COALESCE())Sub QueryIdentity ColumnSequence objectDifference between sequence and identity columnSQL Server ClausesWHERE ClauseOrder By ClauseTop N ClauseGroup By ClauseHaving ClauseDifference between Where and HavingSQL Server OperatorsArithmetic OperatorsComparison OperatorsLogical OperatorsBitwise OperatorsAny OperatorsAll OperatorsUnion OperatorsUnion All OperatorsDifference between Union and Union AllIntersect OperatorExcept OperatorDifference between Except and IntersectJoinsInner JoinLeft JoinRight JoinFull JoinSelf JoinCross JoinViewsWhat are views?Create views using SSMSIndexed ViewsComplex ViewsCheck Option in ViewCheck Encryption in ViewSchema Binding Option in ViewRead-only ViewsUpdatable ViewsAdvantages and disadvantages of viewsCreate multiple views on one tableCan we implement index on views?Can we Perform Insert, update, delete operation on views?Stored Procedure and FunctionsWhat are Stored Procedures?Why we use stored procedures?Passing parameters to Stored procedureUser-Defined FunctionsDifference between UDF and Stored procedurePre-Defined Functions@@Indentity and Scope_IndentityNULLIF, ISNULL and COALESCE

What is the difference between primary key and candidate key?

The primary key and candidate key are both concepts used in database design to uniquely identify rows in a table. However, there are some differences between them:

Primary Key:

  1. A primary key is a special type of candidate key that is chosen to uniquely identify each row in a table.
  2. In a table, there can be only one primary key.
  3. The primary key must be unique and non-null for each row.
  4. It provides a means to identify and access individual rows efficiently.
  5. By default, a primary key constraint enforces both uniqueness and non-nullability.

Candidate Key:

  1. A candidate key is a set of one or more columns that can uniquely identify a row in a table.
  2. A table can have multiple candidate keys.
  3. Each candidate key must be unique and non-null for each row.
  4. It represents a potential choice for the primary key of a table.
  5. Candidate keys help in identifying and distinguishing rows.
  6. A candidate key may or may not be selected as the primary key based on factors such as data dependencies, business rules, and design considerations.

In summary, a candidate key is a set of columns that can uniquely identify a row, whereas a primary key is the chosen candidate key that uniquely identifies each row in a table. The primary key is the main identifier for a table, while candidate keys are alternative choices for identifying rows.