23-11-2012, 03:02 PM
Data Definition Language Commands and Integrity constraints
Select Command.doc (Size: 291.5 KB / Downloads: 37)
Theory: The Data Definition Language (DDL) is used to create and destroy databases and database objects. These commands will primarily be used by database administrators during the setup and removal phases of a database project.
CREATE: Create command is used to create different database objects like table, view etc.
ALTER: Once you've created a table within a database, you may wish to modify the definition of it. The ALTER command allows you to make changes to the structure of a table without deleting and recreating it. Take a look at the following command:
General Syntax:
Alter table tablename add columnname datatype | alter column datatype | drop column columnname
DROP: The final command of the Data Definition Language, DROP, allows us to remove entire database objects from our DBMS. For example, if we want to permanently remove the personal_info table that we created, we'd use the following command
General Syntax:
Drop table tablename;
Integrity Constraints:
1) NOT NULL Constraint: When column is defined as a NOT NULL then that column becomes mandatory column i.e value must be entered in that column for each row.
Syntax: columnname datatype(size) NOT NULL
2) Primary key constraint: This constraint ensures that data entered in the table column is unique across the entire table. None of the cells belonging to the column are left empty.
Syntax: columnname datatype(size) Primary key