All SQL
All SQL
Constraint Description
NOT NULL values cannot be null
UNIQUE Constraint
CREATE TABLE Colleges (
college_id INT NOT NULL UNIQUE,
college_code VARCHAR(20) UNIQUE,
college_name VARCHAR(50)
);
DEFAULT Constraint
CREATE TABLE College (
college_id INT PRIMARY KEY,
college_code VARCHAR(20),
college_country VARCHAR(20) DEFAULT 'US'
);
Example
Rename a Table
We can change the name of a table using the ALTER TABLE command with
the RENAME clause.
ALTER TABLE Customers
RENAME TO New_customers;
Syntax
RENAME TABLE table-Name TO new-Table-Name
b. DROP: It is used to delete both the structure and record stored in the table.
Syntax
Example
c. ALTER: It is used to alter the structure of the database. This change could be either
to modify the characteristics of an existing attribute or probably to add a new
attribute.
Syntax:
ADVERTISEMENT
EXAMPLE
d. TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.
Syntax:
Example: