Delete: The DELETE command is used to remove rows from a table. A
WHERE clause can be used to only remove some rows. If no WHERE condition is
specified, all rows will be removed. After performing a DELETE operation you
need to COMMIT or ROLLBACK the transaction to make the change permanent or to
undo it.
Example- To delete any
specific row you would use:
DELETE FROM MyTable WHERE
id=5
This would delete the row
with the id = 5 If no conditions are matched it would delete all rows
Drop: The DROP command removes a table from the database. All the
tables' rows, indexes and privileges will also be removed. No DML triggers will
be fired. The operation cannot be rolled back.
Example- DROP TABLE
MyTable
This would delete the
whole table and its constraints.
ROLLBACK:
To undo the work/changes that are committed or done by COMMIT clause we use the ROLLBACK Command. It is reverse of COMMIT. It rollbacks all the changes of the current transactions. In other words ROLLBACK restore the state of the database to the last commit point.
Syntax
DELETE FROM table_name
ROLLBAC
COMMIT:
Whatever changes we have made/ done in our transaction cannot be fixed until we commit that transaction and this can be possible by using COMMIT statement. In other words it will make our changes permanent that cannot be rolled back.
Syntax
To undo the work/changes that are committed or done by COMMIT clause we use the ROLLBACK Command. It is reverse of COMMIT. It rollbacks all the changes of the current transactions. In other words ROLLBACK restore the state of the database to the last commit point.
Syntax
DELETE FROM table_name
ROLLBAC
COMMIT:
Whatever changes we have made/ done in our transaction cannot be fixed until we commit that transaction and this can be possible by using COMMIT statement. In other words it will make our changes permanent that cannot be rolled back.
Syntax
COMMIT;
_____________________________________________________________________________
_____________________________________________________________________________
Alter: Alter is a SQL command that is used to
modify, delete or add a column to an existing table in a database. Alter is considered
as a DDL statement. Commands that are used to define the structure of a
database (database schema) are called DDL statements. Following is the typical
syntax of an alter statement that is used to add a column to an existing table.
ALTER TABLE
tableName
ADD
newColumnName dataTypeOfNewColumn
In here tableName is the name of the
existing table that needs to be altered and newColumnName is the name given to
the new column that is added to the table. dataTypeOfNewColumn provides the
data type of the new column.
Update:
Update is a SQL command
that is used to update existing records in a database. Update is considered as
a DML statement. Commands that are used to manage data without altering the
data base schema are called DML statements. Following is the typical syntax of
an update statement.
UPDATE
tableName
SET
column1Name=value1,
column2Name=value2, …
WHERE
columnXName=someValue
In the above example
tableName should be replaced with the name of the table you want to modify the
records in. The column1Name, column2Name in the SET clause are the names of the
columns in the table in which the values of the record that needs to be
modified. value1 and value2 are the new values that should be inserted in the
record. WHERE clause specifies the set of records needs to be updated in the
table. WEHRE clause could also be omitted from the UPDATE statement. Then all
the records in the table would be updated with the values provided in the SET
clause.
No comments:
Post a Comment