Calendar
May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  
Statistic
Earn Cash by using your Blog

Posts Tagged ‘data definition language’

Learning DDL in Oracle

About DDL or Data Definition Language is a language used to define the data definition. Consists of commands to create, modify or delete the table and its columns and its constituent data types, as well as the commands to define the relationship and limits the data.

the types of DDL in the oracle, namely:

A. CREATE TABLE

Used to create tables. Syntax is generally as follows:

CREATE TABLE [schema], table (column datatype [DEFAULT expr] [, ...]);

Example of a table is:

create table MHS (

nim varchar2 (7),

name varchar2 (15),

CPI number (3.2),

jml_e number (2)

);

Then to see the existing tables, can write

Select * from tab;

Then to see the description of the table, can write

Desc MHS;

2. ALTER TABLE
ALTER TABLE statement is used to:
-> Adding a new column
To add a new column, the following general syntax:

ALTER TABLE table ADD (column datatype [DEFAULT expr] [, column datatype] …);

alter table item add / modify the brand varchar (50);

add to add a field, while the Modify to edit the field;

alter table rename column name> table> name> field>;

to change the name of the field

MHS alter table add the address varchar (20);

-> Delete column
DROP COLUMN clause is used to remove the columns that are not needed anymore in the table. For example, to delete the address in the table above MHS.

MHS alter table drop column address;

-> Modify an existing column
We can modify the column by changing the data type, size and default values.
The syntax of the ALTER TABLE command to modify the columns as follows:

Modify the ALTER TABLE table (column datatype [DEFAULT expr] [, column datatype] …);

Example:

Modify the ALTER TABLE student (jml_e number (5));

Table altered.

3. DROP TABLE
Used to eliminate the table. Perform the deletion table with the DROP command, then do the following:
-> All the data and the structure of the table is deleted
-> All pending transactions will be commit
-> All indexes will be removed
-> The command can not drop this on-rollback
For example, if you want to remove MHS table, then that should be addressed:

DROP TABLE MHS;

4. RENAME
Used to merubaha name of an object (table, view, sequence or synonim). For example, if we want to change the student table, then the command to do are:

RENAME TO MHS students;

CREATE, ALTER, and DROP DATABASE

SQL (Structured Query Language) is a language used to access the database. Almost all understand the language of SQL database software. Therefore the software and database SQL commands with one another more or less similar.

The types of commands in the SQL itself is divided into three:

  • DDL (Data Definition Language)
  • DML (Data Manipulation Language)
  • DCL (Data Control Language)

DDL (Data Denifition Language) is a type of SQL command associated with defining objects in a database or the database itself. There are three basic commands in this DDL statement, theCREATE, ALTER, and DROP.

DML (Data Manipulation Language) is a type of SQL command associated with the manipulation of data and records in a database. The basis of the DML commands such as SELECT, INSERT, UPDATE, DELETE, and so forth.

DCL (Data Control Language) is a type of SQL statements that relate to safety or security of a database. DCL is an example of the basic commands GRANT and REVOKE.

Of the many options database software, one of which is often the mainstay of the webmaster isMySQL. Because other than freeware, MySQL is also suitable for people who are just learning the world of the database’s like me.

MySQL command types were divided into three, namely DDL, DML, DCL. We will discuss one by one starting from the DDL. One of the DDL statement that is certain to use the CREATE, ALTER, and DROP DATABASE.

CREATE DATABASE

General form of the CREATE DATABASE:

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name</span> CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name</span>
  2.     <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>[create_specification] …</span> [Create_specification] …</span>
  3. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>create_specification:</span> create_specification:</span>
  4.     <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>[DEFAULT] CHARACTER SET [=] charset_name</span> [DEFAULT] CHARACTER SET [=] charset_name</span>
  5.   <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| [DEFAULT] COLLATE [=] collation_name</span> | [DEFAULT] COLLATE [=] collation_name</span>

Function CREATE DATABASE statement is to create a new database. This command functions the same as the CREATE SCHEMA statement. Run the MySQL console, type the command SHOW DATABASES to see a list of any existing database in MySQL.

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>SHOW DATABASES;</span> SHOW DATABASES;</span>
  2. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>
  3. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| Database |</span> | Database |</span>
  4. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>
  5. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| information_schema |</span> | Information_schema |</span>
  6. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| mysql |</span> | Mysql |</span>
  7. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| phpmyadmin |</span> | Phpmyadmin |</span>
  8. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| test |</span> | Test |</span>
  9. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>

It will show all existing databases in MySQL. To create a MySQL database on the console type theCREATE DATABASE database_name;. Suppose we will create a new database with the name of the university.

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>CREATE DATABASE universitas;</span> CREATE DATABASE university;</span>

Use the SHOW DATABASES command to see which database we just created.

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>SHOW DATABASES;</span> SHOW DATABASES;</span>
  2. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>
  3. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| Database |</span> | Database |</span>
  4. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>
  5. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| information_schema |</span> | Information_schema |</span>
  6. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| mysql |</span> | Mysql |</span>
  7. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| phpmyadmin |</span> | Phpmyadmin |</span>
  8. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| test |</span> | Test |</span>
  9. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| universitas |</span> | University |</span>
  10. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>

ALTER DATABASE

Common forms of ALTER DATABASE:

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>ALTER {DATABASE | SCHEMA} [db_name]</span> ALTER {DATABASE | SCHEMA} [db_name]</span>
  2.     <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>alter_specification …</span> alter_specification …</span>
  3. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>alter_specification:</span> alter_specification:</span>
  4.     <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>[DEFAULT] CHARACTER SET [=] charset_name</span> [DEFAULT] CHARACTER SET [=] charset_name</span>
  5.   <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| [DEFAULT] COLLATE [=] collation_name</span> | [DEFAULT] COLLATE [=] collation_name</span>

ALTER DATABASE statement function is to change the characteristic of a database is usually stored in the file db.opt. This command is rarely used. ALTER DATABASE has the same function with the ALTER SCHEMA.

DROP DATABASE

General forms of the DROP DATABASE:

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>DROP {DATABASE | SCHEMA} [IF EXISTS] db_name</span> DROP {DATABASE | SCHEMA} [IF EXISTS] db_name</span>

DROP DATABASE statement function is to remove the database. One thing to note is, MySQL is not going to confirm the removal of the database if you use this statement. Therefore you must be careful to use this statement because all the records, tables and objects that exist in your database will also be lost with the database to delete. Suppose we will remove the university database that we created earlier.

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>DROP DATABASE universitas;</span> DROP DATABASE university;</span>

Use the SHOW DATABASES command to see a list of databases.

  1. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>SHOW DATABASES;</span> SHOW DATABASES;</span>
  2. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>
  3. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| Database |</span> | Database |</span>
  4. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>
  5. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| information_schema |</span> | Information_schema |</span>
  6. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| mysql |</span> | Mysql |</span>
  7. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| phpmyadmin |</span> | Phpmyadmin |</span>
  8. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>| test |</span> | Test |</span>
  9. <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left”>+——————–+</span> + ——————– +</span>

OK ..! So first tutorial this time.

 Database_name CREATE SCHEMA has the same function with the CREATE DATABASE database_name. Try it! REFERENCES

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:

  1. CREATE
  2. ALTER
  3. RENAME
  4. DROP
  5. 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:

  1. Must begin with alphabetic
  2. name length must be 1-30 characters
  3. Can only use AZ, az, 0-9, _, $, and #
  4. 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
  5. 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:

  1. Creating rules in the table
  2. Avoid the pen-delete-an on the table if the table has a dependence
  3. Constraint Type is valid is as follows:
  1. PRIMARY KEY
  2. FOREIGN KEY
  3. NOT NULL
  4. UNIQUE
  5. CHECKED

Guidelines in using Constraint:

  1. We can provide the constraint name manually or can be generates by the Oracle Server using the command SYS_cn
  2. Constraint-making can be conducted simultaneously at the time we create a table or the table is completed by using the Alter Table command
  3. Defining the constraint can be performed on the column level or table level
Constraint syntax is as follows:

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

Glance About Sybase Power Designer 11

Sybase Power Designer 11 is a modeling tool released by Sybase for
build an information system that is fast, structured and effective. Sybase Power Designer 11
supports multiple modeling as follows:
• Requirements Management
• Business Process
• Data Modelling
• XML Modelling
• Application Modeling with UML
• Information Liquidity Modeling
• Integrated Modelling
In this tutorial we will try to use Power Designer to do the modeling
data (data modeling) for then we will use to perform database design.
Simply put, to perform data modeling in Power Designer, we have to begin at
level Conceptual Data Model, where the data modeling is done using the method Entity
Relationship Diagram. In the CDM, data type that is used is general and not specific
against a particular database.
The second stage is to create a Physical Data Model (PDM) PDM is a specific form of
CDM that we have built. Power Designer has a lot of support for the target database, sowe
not to be confused about the type - the type of data used, because the Power Designer will
adjust as the data type that we defined earlier in the stage of the CDM.
The last stage is the script generates Data Definition Language (DDL) of the PDM that has been
is made. Through this we can generate the DDL objects - database objects (tables, triggers, views,
procedure) then DDL scripts so that we can execute the software of other databases such as Oracle
or MySQL, or we can also create a connection and execute it directly via the PowerDesigner.