View In SQL | Types Of Views In SQL Server [2021]

In this article, We’ll go over the different types of views in SQL Server through examples. In addition, we will learn how to create, alter, update, and delete views in SQL Server.

View in SQL Server
Views in SQL Server

What is a view in SQL?

Views in SQL Server are nothing more than virtual tables based on the result sets of SQL statements from one or more tables.

Continue reading “View In SQL | Types Of Views In SQL Server [2021]”

SQL Delete Cascade – SQL query to delete parent-child referenced rows

In this article, we will learn DELETE CASCADE rules in SQL Server with foreign key constraint having multiple examples.

OVERVIEW – SQL DELETE CASCADE

1.  DELETE CASCADE : In the SQL server, when we create a foreign key using the delete cascade option, it deletes all the related rows from the child table when the referenced row is deleted from the parent table having primary key constraint.

SQL-DELETE-CASCADE
SQL-Delete cascade rule

The following are the SQL scripts that create a parent (Departments), child (Employees) table, and a foreign key on the child table without the delete cascade rule.

Continue reading “SQL Delete Cascade – SQL query to delete parent-child referenced rows”

Primary Key Constraint In SQL Server

What is the primary key in SQL Server?

In SQL Server, a  Primary Key  is a field or column which uniquely identifies each and every record in a table.

    • A primary key column doesn’t allow to insert  null  or duplicate values.
    • A Primary key can consist of up to 16 columns.
    • A table can have only one primary key which can be applied on single or multiple columns.
    • The primary key consist of multiple columns or fields is known as the Composite primary key.
    • A Primary Key constraint can be applied to the columns having any data types.
    • A primary key by default creates a clustered index on the column.

A primary key can be created at the column or table level.

Primary Key Constraint in SQL Server
Primary Key Constraint in SQL Server

Syntax to create a primary key

The following are the syntax to create a primary key in SQL server.

Continue reading “Primary Key Constraint In SQL Server”