ddl script
5 Command DDL (Data Definition Language)
Post an this is my project work on the SQL DML command … may be useful for readers wrote … ![]()
Overview of the SQL …
SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases. The entire database applications on the market, both free and is licensed, adopt the SQL language for database processing. There are two types of command in SQL, the DDL and DML.
DDL (Data Definition Language) is a SQL command associated with the definition of a database and tables.Some basic commands are included in the DDL, among others.
A. CREATE
Function: CREATE Command is working to create a database or create a table inside the database.
Syntax: CREATE database_name database;
Parameters: -
Example: CREATE pharmacy database;
Explanation: CREATE command above will create a database with the name of the pharmacy.
2. SHOW
Function: This function SHOW Command to display the database or table that we created earlier.
Syntax: SHOW databases;
Parameters: -
Example: SHOW databases;
Explanation: The SHOW command above will show all the existing database.
3. USE
Function: USE Command is working to open / activate / enter the database we have created. Once we enter into the database we have created, then we can manipulate existing data, including to create a table in the database.
Syntax: USE database_name;
Parameters: -
Example: USE pharmacies;
Explanation: The command above will enable the database with the name of the pharmacy so that we can manipulate the data.
4. ALTER
Function: ALTER Command is working to change the structure of a table. Change here is not simply renew the existing table structure, but also changed the name of the field, adding a primary key, change the field type, or delete fields that have been made previously.
Syntax: ALTER TABLE table_name parameter_option;
Parameters: add, modify, drop
Example: ALTER TABLE ADD medication price int (6);
Explanation: The command above will add a field into the price of the drug table.
5. DROP
Function: DROP Command is working to remove, either database, table, or field that has been entered into the table.
Syntax: DROP TABLE table_name;
Parameters: -
Example: DROP TABLE supplier;
Explanation: The command above will remove the table supplier in the pharmacy database.
Operation DDL (Data Definition Language)
DDL is a language that is used to manage or define a table.
Statements is:
- CREATE
- ALTER
- RENAME
- DROP
- TRUNCATE
In this article we will discuss about how to make table using the CREATE
In the manufacture of table and column names are the requirements to be met are:
- Must begin with alphabetic
- name length must be 1-30 characters
- Can only use AZ, az, 0-9, _, $, and #
- The table name and the name of His column should not be the same as the names and columns in other tables, the same user
- May not use names that have been reserved by the Oracle Server
such as: FROM, INSERT, WHERE, and others
Syntax is as follows:
CREATE TABLE [table_name] (
[Column_name] [type_kolom] [size column]
)
-Create a table MsEmployee
CREATE TABLE MsEmployee
(
EmployeeID CHAR (5),
EmployeeName VARCHAR (20),Email varchar2 (20),
Address varchar2 (30),
Salary NUMBER (10,2))
-Create a table TrHeaderTransaction
CREATE TABLE TrHeaderTransaction
(
TransactionID CHAR (5),
CustomerlD CHAR (5),
TransactionDate DATE)
Keep in mind, the table above belom interconnected. We can connect the two tables by using Constraint.
Usefulness CONSTRAINT:
- Creating rules in the table
- Avoid the pen-delete-an on the table if the table has a dependence
- Constraint Type is valid is as follows:
- PRIMARY KEY
- FOREIGN KEY
- NOT NULL
- UNIQUE
- CHECKED
Guidelines in using Constraint:
- We can provide the constraint name manually or can be generates by the Oracle Server using the command SYS_cn
- Constraint-making can be conducted simultaneously at the time we create a table or the table is completed by using the Alter Table command
- Defining the constraint can be performed on the column level or table level
CONSTRAINT [nama_constraint] [TYPE_CONSTRAINT]
-Making MsEmployee tables by using column-level constraint
CREATE TABLE MsEmployee
(
EmployeeID CHAR (5) PRIMARY KEY NOT NULL,
Cs002 CONSTRAINT CHECK (LENGTH (EmployeeID) = 5),
EmployeeName VARCHAR2 (20) NOT NULL,
Email varchar2 (20) UNIQUE,
Address varchar2 (30) NOT NULL,
Salary NUMBER (10,2) NOT NULL)
-Making TrHeaderTransactiondengan tables using table-level constraint
CREATE TABLE TrHeaderTransaction
(
TransactionID CHAR (5) NOT NULL,
EmployeeID CHAR (5) NOT NULL,
TransactionDate DATE NOT NULL,
AAB CONSTRAINT PRIMARY KEY (TransactionID),
Cs005 CONSTRAINT CHECK (LENGTH (TransactionID) = 5),
Ngehubungin CONSTRAINT FOREIGN KEY (EmployeeID) REFERENCES MsEmployee (EmployeeID) ON DELETE CASCADE)
Explanation:
- NOT NULL CONSTRAINT is used to ensure the column is filled so that no value is empty
- CONSTRAINT CHECKED used to check whether the data has been in accordance with predefined rules. In the above examples should be 5 characters long TransactionID not be less or more
- UNIQUE CONSTRAINT is used to ensure there are no charging value or the same name on other data so as to prevent duplication of data
- “Ngehubungin CONSTRAINT FOREIGN KEY (EmployeeID) REFERENCES MsEmployee (EmployeeID)” is used to link tables by table TrHeaderTransaction MsEmployee using EmployeeID EmployeeID as the connecting which is PRYMARY MsEmployee KEY of the table. Where Table MsEmployee as a parent and a child TrHeaderTransaction
- CONSTRAINT ON DELETE CASCADE is used to ensure the event’s pen-delete the parent table row, child rows referencing the value of the data is also deleted but not vice versa.
In Oracle we can also use DEFAULT Syntax as initial value data
example:
CREATE TABLE EMPLOYEES2 (
Hire_Date DATE DEFAULT SYSDATE / * hire_date column filled with a date now without doing the INSERT * /
)
Copying or copy a table
In addition to creating the table above we can also make a table of the contents and data types together with other tables
example:
CREATE MsEmp2
U.S.
SELECT * FROM MsEmployees
we also can determine which columns are willing to be copied
CREATE MsEmp2
U.S.
EmloyeeId SELECT, FROM EmployeeName MsEmployees
above query is used to copy the table along with its contents, if we want to copy only the table columns without data content that is by adding WHERE 1 = 2
example:
CREATE MsEmp2
U.S.
MsEmployees SELECT * FROM WHERE 1 = 2
Database Concepts
Definition of Database
The database is a collection of related data
stored / organized jointly, in the form
in such a way, and without repetition (redundancy) that
not need to be 6 be recovered by
quickly and easily to meet various needs.
The purpose of the database or databases are:
a. Ease, accuracy and speed in decision
back data.
b. To handle the large amounts of data.
c. Ease of data access.
d. Eliminates redundancies and data inconsistencies.
2.8.2 Normalization
Become an accepted formal process to determine atributatribut
which should be grouped in bersamasama
in a relation.
Theory of Language Database
In database programming is divided into two kinds:
a. Data Definition Language (DDL)
DDL has a role:
1. Creating or Deleting Database.
2. Create, Change or Delete a Table.
3. Defining Constraints (Primary key, Foreign Key,
etc.)
b. Data Manipulation Language (DML)
DML has a role:
1. adding data
2. deleting data
3. changing the data
4. displaying the data








