Ex 4
Ex 4
These commands can be used to define, alter, and delete database structures
such as tables, indexes, and schemas.
1) CREATE
To create a new table in the database
Syntax:
CREATE TABLE table_name (column_name1 data type(size),
column_name2 data type(size), column_name3 data type(size),…);
2) DROP
Delete table from the database.
Syntax
DROP TABLE table_name;
3) ALTER
Alter the structure of the database
Syntax:
ALTER TABLE table_name
ADD/ DROP / MODIFY column_name datatype;
4) TRUNCATE
Removes all records from a table, leaving only the schema intact.
Syntax
TRUNCATE TABLE table_name;
5) RENAME
Rename an object or the name of the table existing in the database
Syntax
RENAME TABLE old_table_name TO new_table_name;
Data Manipulation Language (DML)
DML statements are used for managing data within the table.
DML commands:
1) INSERT
Insert data into a table
Syntax:
INSERT INTO table_name (column1, column2, ...) VALUES (value1,
value2, ...);
2) UPDATE
Update existing data within a table
Syntax
UPDATE table_name SET column1 = value1, column2 = value2 WHERE
condition;
3) DELETE
Delete records from a database table
Syntax
DELETE FROM table_name WHERE condition;
Inference:
Learnt about DDL and DML commands, its types, syntax and its uses.