SQL PRIMARY KEY Constraint

The PRIMARY KEY constraint is used to uniquely identify each row in a table. A PRIMARY KEY must contain unique values and it can’t contain a null value. A table can have only one primary key. We can use multiple columns or fields to define a primary key, such primary key is known as composite … Read more

Categories SQL

SQL CONSTRAINTS

The SQL constraints are the rules enforced on the data in a table. A constraint can be specified with the CREATE TABLE statement at the time table creation or we can specify it with the ALTER TABLE statement after the table creation. Syntax: CREATE TABLE <em>tableName</em> ( <em>columnName1 datatype</em>(<em>size</em>) <em>constraintName</em>, <em>columnName2 data_type</em>(<em>size</em>) <em>constraintName</em>, <em>columnName2 data_type</em>(<em>size</em>) … Read more

Categories SQL

SQL TRUNCATE Table

The TRUNCATE TABLE command is used to remove the all rows from an existing table. Syntax: TRUNCATE TABLE tableName;  Example: TRUNCATE TABLE EMPLOYEE;TRUNCATE TABLE EMPLOYEE; Output: Table truncated.Table truncated. Difference between TRUNCATE, DELETE and DROP commands: The DELETE statement is used to delete or remove all the rows from the table. We can use where … Read more

Categories SQL

SQL DELETE from table

The DELETE statement is used to delete or remove all the rows from the table. Syntax: DELETE FROM tableName; Example: DELETE FROM EMPLOYEE;DELETE FROM EMPLOYEE; Output: 3 row(s) deleted.3 row(s) deleted. The DELETE statement with where condition is used to delete or remove the specific rows from the table. Syntax: DELETE FROM tableName [WHERE condition]; … Read more

Categories SQL

SQL DROP Table

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 the available information in the table will be lost, so use it carefully. Syntax: DROP TABLE tableName;   Example: DROP TABLE EMPLOYEE;DROP TABLE EMPLOYEE; Output: Table dropped.Table dropped.   Next Topic: … Read more

Categories SQL

SQL RENAME Table

The RENAME TABLE statement is used to change the table name. Syntax: RENAME tableName TO newTableName; We can also use the ALTER TABLE statement to change the table name. Syntax: ALTER tableName RENAME TO newTableName; Example: RENAME EMPLOYEE1 TO EMPLOYEE2;   Or   ALTER EMPLOYEE1 RENAME TO EMPLOYEE2;RENAME EMPLOYEE1 TO EMPLOYEE2; Or ALTER EMPLOYEE1 RENAME TO EMPLOYEE2; Example: Statement processed.Statement processed.   … Read more

Categories SQL

SQL COPY Table

The SELECT INTO statement is used to copy a table data into another table. Syntax: Select * into destinationTable from sourceTable; Example: Select * into EMPLOYEE1 from EMPLOYEE;   Next Topic: SQL RENAME Table with example. Previous Topic: SQL ALTER Table with example.  

Categories SQL

SQL ALTER Table

The ALTER TABLE statement is used to add, delete or modify a table column. It can also be used to rename a table and to add or drop constraints on a table. Syntax of ALTER TABLE to add a new column: ALTER TABLE tableName ADD columnName datatype; Example: Syntax of ALTER TABLE to add multiple … Read more

Categories SQL

SQL CREATE Table

Table: A table in SQL is a set of data which is systematically displayed in rows and columns. The CREATE TABLE Statement is used to create a new table. Syntax: CREATE TABLE tableName (columnName1 datatype, columnName2 datatype, …   columnNameN datatype);CREATE TABLE tableName (columnName1 datatype, columnName2 datatype, … columnNameN datatype); Example: CREATE TABLE EMPLOYEE ( … Read more

Categories SQL

SQL DROP Database

To delete or drop an existing database we have to use DROP DATABASE statement. Syntax: DROP DATABASE databaseName; Example: DROP DATABASE w3schools_db;   Next Topic: SQL CREATE Table with example. Previous Topic: SQL SELECT Database with example.  

Categories SQL