The PRIMARY KEY constraint is used to uniquely identify each row in a table. A PRIMARY KEY can’t have any null value and must have unique values. There can only be one primary key in a table. We can use multiple columns or fields to define a primary key, such a primary key is known […]
SQL constraints are rules that are applied to the data in a table. We can specify a constraint with the CREATE TABLE statement at the time of table creation or with the ALTER TABLE statement after the table has been created. Syntax: Commonly used constraints in SQL: 1. SQL PRIMARY KEY Constraint. 2. SQL FOREIGN […]
The TRUNCATE TABLE command is used to remove all rows from an existing table.Syntax: Example: Output: Difference between TRUNCATE, DELETE and DROP commands: To delete or remove all rows from a table, use the DELETE statement. The where clause can be used to delete specific rows. We can roll back the DELETE operation. TRUCATE is […]
The DELETE statement is used to delete or remove all the rows from the table.Syntax: Example: Output: The DELETE statement with where the condition is used to delete or remove the specific rows from the table. Example: output:
The DROP TABLE statement is used to delete an existing table definition, indexes, constraints, access privileges and all associated data. Note: When a table is deleted, all of the information in it is lost, so use it with caution. Syntax:DROP TABLE tableName; Example: Output: Table dropped.
The RENAME TABLE statement is used to change the table name.Syntax: We can also use the ALTER TABLE statement to change the table name.Syntax: Example: Example: Statement processed.
To add, delete, or modify a table column, use the ALTER TABLE statement. It can also be used to rename a table as well as add and remove constraints. Syntax of ALTER TABLE to add a new column: ALTER TABLE tableName ADD columnName datatype; Example: Syntax of ALTER TABLE to add multiple columns: Example: Output: […]