Data Definition Language
Data Definition Language
History
The term DDL was first introduced in relation to the Codasyl database model, where the schema of the database was written in a Data Description Language describing the records, fields, and "sets" making up the user Data Model. Later it was used to refer to a subset of SQL for creating tables and constraints. SQL-92 introduced a schema manipulation language and schema information tables to query schemas. These information tables were specified as SQL/Schemata in SQL:2003. The term DDL is also used in a generic sense to refer to any formal language for describing data or information structures.
SQL
Unlike many data description languages, SQL uses a collection of imperative verbs whose effect is to modify the schema of the database by adding, changing, or deleting definitions of tables or other objects. These statements can be freely mixed with other SQL statements, so the DDL is not truly a separate language. The most commonly encountered statement is CREATE TABLE.
CREATE statements
Create - To make a new database, table, index, or stored query. A CREATE statement in SQL creates an object inside of a relational database management system (RDBMS). The types of objects that can be created depends on which RDBMS is being used, but most support the creation of tables, indexes, users, synonyms and databases. Some systems (such as PostgreSQL) allow CREATE, and other DDL commands, inside of a transaction and thus they may be rolled back. CREATE TABLE statement Perhaps the most common CREATE command is the CREATE TABLE command. The typical usage is: CREATE [TEMPORARY] parameters]. TABLE [table name] ( [column definitions] ) [table
Column Definitions: A comma-separated list consisting of any of the following Column definition: [column name] [data type] {NULL | NOT NULL} {column options} Primary key definition: PRIMARY KEY ( [comma separated column list] ) CONSTRAINTS: {CONSTRAINT} [constraint definition] RDBMS specific functionality
For example, the command to create a table named employees with a few sample columns would be: CREATE TABLE employees ( id INTEGER first_name CHAR(50) last_name CHAR(75) dateofbirth DATE );
DROP statements
Drop - To destroy an existing database, table, index, or view. A DROP statement in SQL removes an object from a relational database management system (RDBMS). The types of objects that can be dropped depends on which RDBMS is being used, but most support the dropping of tables, users, and databases. Some systems (such as PostgreSQL) allow DROP and other DDL commands to occur inside of a transaction and thus be rolled back. The typical usage is simply: DROP objecttype objectname. For example, the command to drop a table named employees would be: DROP TABLE employees; The DROP statement is distinct from the DELETE and TRUNCATE statements, in that they do not remove the table itself. For example, a DELETE statement might delete some (or all) data from a table while leaving the table itself in the database, whereas a DROP statement would remove the entire table from the database.
ALTER statements
Alter - To modify an existing database object. An ALTER statement in SQL changes the properties of an object inside of a relational database management system (RDBMS). The types of objects that can be altered depends on which RDBMS is being used. The typical usage is: ALTER objecttype objectname parameters. For example, the command to add (then remove) a column named bubbles for an existing table named sink would be: ALTER TABLE sink ADD bubbles INTEGER; ALTER TABLE sink DROP COLUMN bubbles;
Other languages
XML Schema is an example of a DDL for XML. Simple Declarative Language Kwalify ...
External links
How to change data type of a column MS SQL - How to change data type of a column [1]
References
[1] http:/ / aspxtutorial. com/ post/ 2010/ 07/ 01/ MS-SQL-How-to-change-the-data-type-of-a-column-using-query. aspx
License
Creative Commons Attribution-Share Alike 3.0 Unported http:/ / creativecommons. org/ licenses/ by-sa/ 3. 0/