0% found this document useful (0 votes)
34 views

Databasequestion

Uploaded by

Shrina Maskey
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Databasequestion

Uploaded by

Shrina Maskey
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Question 1:

DDL Represents "Data Definition Language." DDL is a language used to describe data
formation and data conversion. For example, DDL commands can be used to add,
delete, or modify tables within a database. DDLs used in database applications are
considered as a subset of SQL, Structured Query Language. However, DDL can also
define other types of data, such as XML.

Data Definition Language has a pre-defined syntax for interpreting data. For
example, to create a new table using SQL syntax, the CREATE command is applied,
followed by table name parameters and column descriptions. DDL can also define the
name of each column and the corresponding data type. Once the table is set, it can
be converted using the ALTER command. If a table is no longer needed, a DROP
command can be used to clear the table.

DDL statements allow you to perform these tasks

CREATE- Data Definition language(DDL)


The main use of create command is to build a new table and it comes with a
predefined syntax. It creates a component in a relational database management
system. There are many implementations that extend the syntax of the command to
create additional elements, like user profiles and indexes.

The general syntax for create command in Data Definition Language is mentioned
below:

CREATE TABLE tablename


Column1 DATATYPE,
Column2 DATATYPE,
Column3 DATATYPE, ……..
ColumnN DATATYPE)
For Example

CREATE TABLE PUPIL


PUPIL_ID CHAR (10),
STUDENT_Name Char (10);
Pupil Table with his ID and name is created by the DDL statement

Generally, the data types often used consists of strings and dates while creating a
table. Every system varies in how to specify the data type.

2. ALTER- Data Definition language(DDL)

An existing database object can be modified by the ALTER statement. Using this
command, the users can add up some additional column and drop existing columns.
Additionally, the data type of columns involved in a database table can be changed
by the ALTER command.

The general syntax of the ALTER command is mentioned below:

For adding a new column

ALTER TABLE table_name ADD column_name


(for renaming a table)

ALTER TABLE table_name RENAME To new_table_name


(for modifying a column)

ALTER TABLE table_name MODIFY column_name data type


(for deleting a column)

ALTER TABLE table_name DROP COLUMN column_name


For Example

Add column to the pupil table

ALTER TABLE PUPIL ADD PHONE NUMBER varchar 97


Before Adding Column

Pupil ID PUPIL_Name
97 Albert
98 Sameer
After Adding Column

PUPIL_ID STUDENT_NAME MOBILE NUMBER


97 ALBERT
98 SAMEER
3. Drop- Data Definition language(DDL)

By the use of this command, the users can delete the database, table or view. A
component from a relational database management system can be removed by a DROP
statement in SQL. There are many systems that allow the DROP and some other Data
Definition Language commands for occurring inside a transaction and then it can be
rolled back.

The object will not be available for use once the DROP statement executed

The General syntax of Drop command is mentioned below:

If you want to delete a table then its syntax and example will be like this

DROP TABLE table_name;


For Example

DROP TABLE Student;


If you want to delete a database then its syntax and example will be like this

DROP DATABASE database_name;


For Example

DROP DATABASE CollegeDB


Truncate- Data Definition language(DDL)
By using Truncate command, users can remove table content, but structure of the
table is kept. In simple language, it removes all the records from the table
structure. Users can’t remove data partially through this command. In addition to
this, every space allocated for the data is removed by Truncate command.

The syntax of the Truncate command is mentioned below:

TRUNCATE TABLE table_name;


For Example

TRUNCATE TABLE Student;


b. you cannot reverse the deletion of a line when using TRUNCATE.

4. Rename
Changing the name of a table, view, sequence, or private dictionary uses a POSSIBLE
statement.

syntax:

Rename_column_existent in the new_gram_name;

renaming you must own a table, cinnamon, view, sequence

5.TAKING TABLE

TRUNCATE TABLE statement to delete all rows in the table.

syntax: TRUNCATE TABLE table name;

while creating a TRUNCATE TABLE database it automatically moves all the space used
by the deleted lines.

b. you cannot reverse the deletion of a line when using TRUNCATE.

Question 2:

DML stands for Data Manipulation Language which basically deals with the
modification of data in the database. DML statements include structured query
statements like select, insert, update, delete, etc. The manipulation of data
includes following operations like storing, modifying, retrieving, deleting, and
updating data in a database.
The SQL commands that deals with the manipulation of data present in the database
belong to DML or Data Manipulation Language and this includes most of the SQL
statements.

Examples of DML:

INSERT – is used to insert data into a table.


UPDATE – is used to update existing data within a table.
DELETE – is used to delete records from a database table.

. INSERT
It is used to insert or add new rows or records in the existing table.

Syntax:

Insert into <table_name>values(<value1>,<value2>,<value3>…….,<valuen>);

Where,

table name: The name of the table In which the data needs to be inserted.
values: values for each column of the table.
To insert values in the table we first need to create a table which is a DDL(Data
definition language) statement. Here, in the below all the examples we have created
a table named students. we will show a demonstration of the DML statement in this
table only. So, let’s start with creating the students table.

Below is the query for creating statement:

create table students (roll_no int,student_name varchar(150),course varchar(150));


Once the table is created we can now insert values into it.

Below is the query for insert statement:

insert into students values(1,'ashish','java');


Insert into students values(2,’rahul’,’C++’);
select * from students;

insert into students values(3,'divya','Arch');


select * from students;

We can also populate one table using another table with the help of select
statement. The only condition is that the table must have the same sets of
attributes.

Syntax to populate the table:

Insert into table_no_first [(column1, column 2…column n)] select column1, column 2…
column n from table_no_two [where condition];

2. SELECT
It used to display the contents of the tables. It is also used to select data from
the database. Below is the syntax to select specified columns and records from the
table.

Select column1,column2,…..column n from table_table;

Where, column 1, column 2….column n are the attributes of the table

Example to demonstrate the above syntax:

select student_name from students;

Below is the query of selecting all records and columns from table:

Select statement with a where clause:

Syntax:

select column 1,column 2,….column n from table_name where [condition]

Where the condition is the specified condition on which basis data is to be


fetched. In the condition we can specify logical operators like >,<,=,LIKE,NOT and
etc.

Example to demonstrate select statement with where clause

select roll_no, student_name, course from students where roll_no=3;

3. Update
It is used to change the existing values of the column i.e, changing the name of
the student or changing the course of any student.
Syntax of update statement:

Update<table_name> set <column_name>=value where <condition>;

Table_name: The name of the table in which the value is to be changed.


condition: condition to get the specified row
Below is the query of the update statement:

update students set roll_no=roll_no+10 where student_name='ashish';

update students12 set student_name='aman' where roll_no=2;


select * from students;

4. Delete
Delete statement is used to delete rows of the table based on the specified
conditions.

Syntax:

delete from <table_name> where <condition>;

table_name: Name of the table from which the data needs to be deleted.
condition: Condition based on which the data is to be deleted.
select * from students;

delete from students where roll_no=11;


select * from students;

delete from students where student_name= 'divya';


delete from students12 where course='Arch';

The above example tells that, when delete command is performed on table students
and wants to delete students_name=’aman’, then it deletes the entire details of
‘aman’ and gives the output of remaining students in the table. Here, one by one we
have deleted all the rows of the table. In the end, the table is only left with the
column’s name and its schema. To delete the schema we have to use a DROP statement
which is a DDL statement.

You might also like