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

SQL - One to One Relationship

In a database, a one-to-one relationship is a type of relationship between two tables where each record in one table is associated with exactly one record in the other table, and vice versa. This relationship is based on a shared key between the two tables, typically a primary key in one table and a foreign key in the other. Here's an example to illustrate a one-to-one relationship:

Consider a database for a company that stores employee information. We have two tables: "Employees" and "EmployeeDetails."

Table: Employees

Table: Employees
EmployeeID (Primary Key) FirstName LastName
1 John Smith
2 Jane Doe
Table: EmployeeDetails
EmployeeID (Foreign Key) Address Phone
1 123 Main St 555-1234
2 456 Elm St 555-5678

In this example, the "Employees" table stores basic information about employees, including their EmployeeID, FirstName, and LastName. The "EmployeeDetails" table stores additional details for each employee, such as their address and phone number.

To establish a one-to-one relationship, the EmployeeID column in the "Employees" table serves as the primary key, and it is also included in the "EmployeeDetails" table as a foreign key. Each EmployeeID in the "Employees" table corresponds to a unique EmployeeID in the "EmployeeDetails" table, and vice versa.

This one-to-one relationship ensures that each employee in the "Employees" table has only one associated record in the "EmployeeDetails" table, and each record in the "EmployeeDetails" table is linked to only one employee in the "Employees" table.

This type of relationship is useful when we want to separate certain attributes into a separate table to avoid data duplication or when we have optional data that doesn't apply to all employees. In this example, the additional details in the "EmployeeDetails" table are not mandatory for all employees, and the one-to-one relationship allows flexibility in storing and managing this optional information.

Overall, a one-to-one relationship establishes a direct and unique association between records in two tables, where each record in one table corresponds to exactly one record in the other table.