You are on page 1of 4

Data Definition Language ( DDL )

Data Definition Language (DDL) is a standard for commands that define the different structures in a
database. There are different types of  DDL statements that are used to create, modify, and remove
database objects such as tables, indexes, and users. Common DDL statements used are 

 CREATE
The create statement is used to create either a new database or a table.

 Syntax For Creating A New Database:-


CREATE DATABASE database_name;

 Syntax For Creating A New Table:-


CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size) );
 ALTER
Alter command is used to do modifications on the existing columns of a table the alter command is
used to perform tasks such as addition, deletion or modification on the columns of the existing tables.

 Syntax to add a column in a table using alter statement:-


ALTER TABLE table_name
ADD column_name datatype (size);

 Syntax to delete a column in a table using ALTER statement


ALTER TABLE table_name
DROP column_name datatype;

 Syntax to change the data type of a column in a table


ALTER TABLE table_name
ALTER COLUMN column_name datatype;
 DROP
In orderto delete/remove or truncate an index, table or entire database in mysql one can make use of
the DROP statement.

 Syntax to delete and index in a table:-


DROP INDEX table_name.index_name;

 Syntax to delete a table:-


DROP TABLE table_name;

 Syntax to delete a database:-


DROP DATABASE database_name;
Drop command is used to just delete the table from the database but if one wants to delete not only
the table but also the data within the table then use of TRUNCATE command would be considered
appropriate.
 Syntax for TRUNCATE:-
TRUNCATE TABLE table_name; 

DATA MANIPULATION LANGUAGE ( DML )


A data manipulation language (DML) is a family of syntax elements similar to a computer
programming language used for performing tasks such as selecting, inserting, deleting and updating
data in a database. It basically is aimed at Performing read-only queries on the data. Various
commands used under DML category are 

SELECT
Select command is used to retrieve the desired data from the database.

SELECT column_name(s) FROM table_name;


INSERT:-
Insert command is used to insert data into the database.

INSERT INTO table_name (column, column1, column2, column3, …)


VALUES (value, value1, value2, value3 …);
UPDATE:-
Update command is used to update the existing data within a table

UPDATE table_name
SET column=value, column1=value1,…
WHERE someColumn=someValue;
DELETE:-
if one desires to delte all the records form the database then use of DELTE command will be
appropriate.

DELETE FROM tableName

WHERE someColumn = someValue;

Data Control Language ( DCL ) commands 


Data control language commands known as the DCL commands in sql are used for authorization of
the database. These commands basically control the access to the stored data within a database.
GRANT and REVOKE are the two commands that are used for access control twords the database. 

GRANT– this command allows the user access privileges to database.


GRANT privilege_name 
ON object_name
TO {user_name |PUBLIC |role_name}
[WITH GRANT OPTION];
REVOKE– this command is used to withdraw the users access priviliges that were once given by the
use of GRANT.
REVOKE privilege_name
ON object_name
FROM {user_name |PUBLIC |role_name} 

DATABASE OBJECTS
 Views
Derived Tables or “Virtual Tables” are also known as Views. They provide an alternative way to look
at the data of one or more tables. This virtual table or view derives its values from the evaluation of a
query expression in a CREATE VIEW statement. The query expression can reference base tables,
other views, aliases, etc. Essentially, a view is a stored SELECT statement, of which you can retrieve
the results at a later time by querying the view as though it were a table.  . A view can be read-only or
updatable. Currently, Point Base supports Read-Only Views.

The definition of each view is stored in PointBase’s system catalog SYSVIEWS. If no errors are
encountered, PointBase adds the view name to the SYSVIEWS catalog table. Additionally, all
referenced columns of all referenced tables will be added to the SYSVIEWTABLES catalog table

 Indexes
Indexes. Indexes are special lookup tables that the database search engine can use to speed up data
retrieval. Simply put, an index is a pointer to data in a table. An index in a database is very similar to
an index in the back of a book 

 Synonyms
Synonyms are a form of database shorthand. 

Synonyms allow the specification of a short reference name for a long, complex object name, e.g.
sys.dba_tablespaces may be shortened to tabspaces by creating a synonym named tabspaces. 

Synonyms allow access to other databases on other nodes of a distributed database network that is
transparent to the system user.

Normally only private synonyms are created by system users – public synonyms are created by
database administrators. 

 Sequences 

Sequences are special database objects used to generate numbers in sequential order, typically to be
stored as values in data rows for a data table.

Primary use:  To generate unique key values for tables that can be used to link to other tables or that
will serve as primary keys (sequence generated primary keys are termed surrogate keys). 

Example:  Use a Order_Number_Sequence for a TestOrders table where the value of the
Order_Number_Sequence must be unique and in numerical sequence.

 Data Dictionary
In SQL Server the data dictionary is a set of database tables used to store information about a
database’s definition.  The dictionary contains information about database objects such as tables,
indexes, columns, datatypes, and views. 

The data dictionary is used by SQL server to execute queries and is automatically updated whenever
objects are added, removed, or changed within the database.

You might also like