Home / Computer / DDL Functions and Examples (Complete)

DDL Functions and Examples (Complete)

Understanding DDL

 Understanding DDL is

Understanding DDL is Data Definition Language which is a computer programming language used to create and modify the structure of a database object, especially in the form of a schema. 19659005] The initial concept of DDL was first introduced in connection with the Codasyl database model where the database schema was written in syntactic language describing records, fields, and sets of user data models. DDL cannot be separated from Structure Query Language (SQL) to display tables, columns, data, and boundaries.

SQL-92 also introduced schema manipulation languages ​​and schema information tables to the request schema. This information table is specified as SQL / Schemata in SQL: 2003. The term DDL is also used in a general sense to refer to any formal language to describe the structure of data or information.

DDL is part of SQL. SQL often uses imperative verbs with normal English such as sentences to implement database modifications. Therefore, DDL does not appear as a different language in SQL database but defines database schema changes.

DDL function

 Definition of DDL and DDL function

DDL or Data Definition Language has various functions in SQL. DDL is basically a programming language for giving commands inside a database structure. DDL is used to create schemas, tables, indexes, and so on. Following is an explanation of the functions of the DDL programming language.

1. As a "Create" Command

The "Create" programming language is used to create objects in SQL.

  • Create database: Used to create a new database.
  • Create function: Used to create functions in the database.
  • Create index: Used to create indexes in the database.
  • Create procedure: Used to create procedures in the database.
  • Create table: Used to create new tables in the database.
  • Create trigger: Used to create a certain trigger or reaction in the database when using entering certain other commands.

2. As a Command to Change

The command in DDL that is used to change the structure in a table is "Alter". Alter is used to modify column shapes, add or replace existing tables.

3. As A Command To Remove

The programming language in DDL is called "Drop". This language is used to create a command to delete objects in a database.

  • Drop database: Used to delete a database.
  • Drop Table: Used to delete tables in a database.

4. As a Command to Delete Objects Quickly

There is a command to delete objects in the database faster namely "Truncate". This command can be used to delete all tables in a database faster than the "Delete" command.

Truncate can more precisely delete records in a table in a more practical way. Imagine you have created a table structure, but you want to replace all the records in it. Truncate can delete all these records without deleting the table structure.

As for other types of DDL commands in SQL that have specific functions. This command is used to define referential integrity relationships, usually implemented as primary keys and foreign key tags in multiple table columns. These two commands can be included in the sentence CREATE TABLE or ALTER TABLE;

Example of DDL

Following are examples of DDL according to function.

1. CREATE TABLE DDL Example

 Definition of DDL and DDL Example

The "Create" command is generally used to create tables in a database using "CREATE TABLE" with the following format :


 CREATE TABLE [ table name ]  ([ column definition]) [ table parameters ]

Next is an example statement for creating employee list tables with DDL in a database:


 CREATE TABLE employees (id INTEGER PRIMARY KEY, first_name VARCHAR (50) not null, last_name VARCHAR (75) not null, fname VARCHAR (50) not null, dataofbirth DATE not null); 

Some CREATE TABLE DDL formats can join DML (data manipulation language), such as CREATE TABLE AS SELECT (CTAS) syntax in SQL.

2. Example of DDL DROP

 Example of DDL DROP

By using the "DROP" command, you can delete an index, table, or display. Components of a relational database management system can be removed with a DROP statement in SQL. There are many systems that allow DROP and several other DDL commands to undo commands that have occurred.

Following are some examples of the syntax of the DDL "DROP" command in SQL:


 DROP TABLE table_name; 

 DROP DATABASE database_name; [1965904444] DROP TABLE Student; 

 DROP TABLE index_name; 

3. ALTER DDL Example

 ALTER DDL Example

Objects already in the database can be modified with the "ALTER" DDL command. Using this command, you can add additional columns and delete existing columns. In addition, the column data types involved in database tables can be changed or modified with the ALTER command.

Examples of general syntax of the ALTER command are as follows:

ALTER TABLE table_name ADD column_name (to add columns )

ALTER TABLE table_name RENAME To new_table_name (to rename a table)

ALTER TABLE table_name MODIFY column_name data type (to modify columns)

ALTER TABLE table_name MODIFY column_name data type (to modify columns)

ALTER TABLE TABLE table_name DROP COLUMN column_name (to delete columns)

4. DDL TRUNCATE Example

 DDL TRUNCATE Example
Using DDL TRUNCATE, you can delete the contents of the table, but the table structure will still be saved. Simply stated, the TRUNCATE command can delete records from a table structure. You cannot delete some data through this command. In addition, every space allocated for data is deleted by the TRUNCATE command.

Following are some examples of the TRUNCATE syntax:


 TRUNCATE TABLE table_name; 

 TRUNCATE TABLE Student; 

to be implemented in SQL. For your clarity, you also need to learn about SQL and DML (Data Manipulation Language). Hopefully this article is useful.

Loading...

Check Also

Disney Plus 4K resolution support: Is it available?

Most modern televisions now support 4K, with 1080p now reserved primarily for budget sets. As …