C B I T: Data Definition Language
C B I T: Data Definition Language
C B I T: Data Definition Language
Technical Seminar
SUbmitted
by
M.Karthik
I B.Tech II Sem
ROLL.NO : 192P1A0569
CERTIFICATE
1. Definition
2. Types of SQL Commands
3. Diagrammatic Representation
2. Data-Definition Language 5
1. Definition
2. Domain Constraints
3. Referential Integrity
4. Assertion
5. Authorization
1. CREATE
2. DROP
3. ALTER
4. TRUNCATE
5. COMMENT
6. RENAME
STRUCTURED QUERY LANGUAGE
Structured Query Language (SQL) as we all know is the database language by the use of
which we can perform certain operations on the existing database and also we can use this
language to create a database. SQL uses certain commands like Create, Drop, Insert etc. to
carry out the required tasks.
These SQL commands are mainly categorized into four categories as:
Though many resources claim there to be another category of SQL clauses TCL –
Transaction Control Language.
Diagrammatic Representation:
Referential Integrity: There are cases where we wish to ensure that a value
that appears in one relation for a given set of attributes also appears in a certain
set of attributes in another relation (referential integrity). Database
modifications can cause violations of referential integrity. When a referential-
integrity constraint is violated, the normal procedure is to reject the action that
caused the violation.
Assertion: An assertion is any condition that the database must always satisfy.
Domain constraints and referential-integrity constraints are special forms of
assertions. When an assertion is created, the system tests it for validity. If the
assertion is valid, then any future modification to the database is allowed only if
it does not cause that assertion to be violated.
The output of the DDL is placed in the data dictionary, which contains metadata—data
about data.
Examples of DDL commands:
CREATE -- is used to create the database or its objects (like table,
index, function, views, store procedure and triggers).
DROP -- is used to delete objects from the database.
ALTER -- is used to alter the structure of the database.
TRUNCATE -- is used to remove all records from a table, including all spaces
allocated for the records are removed.
COMMENT -- is used to add comments to the data dictionary.
RENAME -- is used to rename an object existing in the database.
SQL | CREATE
CREATE DATABASE
A Database is defined as a structured set of data. So, in SQL the very first step to store
the data in a well-structured manner is to create a database. The CREATE
DATABASE statement is used to create a new database in SQL.
Syntax:
CREATE TABLE
We have learned above about creating databases. Now to store the data we need a table
to do that. The CREATE TABLE statement is used to create a table in SQL. We know
that a table comprises of rows and columns. So while creating tables we have to provide
all the information to SQL about the names of the columns, type of data to be stored in
columns, size of the data etc. Let us now dive into details on how to use CREATE
TABLE statement to create tables in SQL.
Syntax:
DROP
DROP is used to delete a whole database or just a table.The DROP statement destroys the
objects like an existing database, table, index, or view.
A DROP statement in SQL removes a component from a relational database management
system (RDBMS).
Syntax:
Examples:
DROP TABLE table_name;
table_name: Name of the table to be deleted.
TRUNCATE
TRUNCATE statement is a Data Definition Language (DDL) operation that is used to
mark the extents of a table for deallocation (empty for reuse). The result of this operation
quickly removes all data from a table, typically bypassing a number of integrity enforcing
mechanisms. It was officially introduced in the SQL:2008 standard.
The TRUNCATE TABLE mytable statement is logically (though not physically)
equivalent to the DELETE FROM mytable statement (without a WHERE clause).
Syntax:
As is any programming languages comments matter a lot in SQL also. In this set we will
learn about writing comments in any SQL snippet.
Comments can be written in the following three formats:
1. Single line comments.
2. Multi line comments
3. In line comments
Syntax:
-- single line comment
-- another comment
SELECT * FROM Customers;
Syntax:
/* multi line comment
another comment */
SELECT * FROM Customers;
In line comments:
In line comments are an extension of multi-line comments, comments can be stated in
between the statements and are enclosed in between ‘/*’ and ‘*/’.
Syntax:
SELECT * FROM /* Customers; */
More examples:
Multi line comment ->
/* SELECT * FROM Students;
SELECT * FROM STUDENT_DETAILS;
SELECT * FROM Orders; */
SELECT * FROM Articles;
Sometimes we may want to rename our table to give it a more relevant name. For this
purpose we can use ALTER TABLE to rename the name of table.
Columns can be also be given new name with the use of ALTER TABLE.
Syntax (Oracle):