SQL CHECK Constraint

SQL CHECK Constraint In SQL, the CHECK constraint is used to limit the values that can be inserted into a column. It ensures that the data inserted into a column meets a certain condition or set of conditions. Here is an example of how to define a CHECK constraint in SQL: CREATE TABLE students ( […]

SQL FOREIGN KEY Constraint

SQL FOREIGN KEY Constraint In SQL, the FOREIGN KEY constraint is used to establish a relationship between two tables. It is a way to enforce referential integrity in a relational database. The FOREIGN KEY constraint ensures that the values in a column or a set of columns of one table match the values in a […]

SQL PRIMARY KEY Constraint

SQL PRIMARY KEY Constraint In SQL, the PRIMARY KEY constraint is used to define a column or a set of columns as the primary key of a table. A primary key is a unique identifier for each row in a table and is used to ensure that the table has no duplicate rows. Here is […]

SQL UNIQUE Constraint

SQL UNIQUE Constraint In SQL, the UNIQUE constraint is used to ensure that the values in a column or a set of columns are unique. When we define a column or a set of columns with the UNIQUE constraint, it means that each value in that column or set of columns must be unique and […]

SQL NOT NULL Constraint

SQL NOT NULL Constraint In SQL, the NOT NULL constraint is used to ensure that a column cannot contain NULL values. When we define a column with the NOT NULL constraint, it means that it is mandatory to provide a value for that column for every row in the table. If we try to insert […]

SQL Constraints

SQL Constraints In SQL, a constraint is a rule that is defined to ensure the integrity of the data in a database. Constraints are used to enforce data validation and maintain data accuracy and consistency. There are different types of constraints in SQL, which include: NOT NULL Constraint: This constraint ensures that a column cannot […]

SQL ALTER TABLE Statement

SQL ALTER TABLE Statement The SQL ALTER TABLE statement is used to modify an existing table in a database. The ALTER TABLE statement can be used to add, modify or delete columns, constraints, indexes, and more. The syntax for the ALTER TABLE statement is as follows: ALTER TABLE table_name [ADD|DROP|MODIFY] column_name data_type [optional_parameters]; Where table_name […]

SQL DROP TABLE Statement

SQL DROP TABLE Statement The SQL DROP TABLE statement is used to remove a table and all its associated objects such as indexes, triggers, constraints, etc. from a database. The syntax for the DROP TABLE statement is as follows: DROP TABLE table_name; Where table_name is the name of the table that you want to drop. […]

SQL CREATE TABLE Statement

SQL CREATE TABLE Statement The SQL CREATE TABLE statement is used to create a new table in a database. The syntax for the CREATE TABLE statement is as follows: CREATE TABLE table_name ( column1 datatype [optional_parameters], column2 datatype [optional_parameters], … columnN datatype [optional_parameters] ); Where table_name is the name of the new table that you […]

Nested if

Nested: if In C programming language, you can use nested if statements to create more complex conditional logic. A nested if statement is simply an if statement inside another if statement. The syntax of a nested if statement is as follows: if (condition1) { // code to execute when condition1 is true if (condition2) { […]