Professional Documents
Culture Documents
Ishita Gupta
Electronics Engineering
191061033
AIM: Study of DDL and DML operations on database Tables using SQL.
TOOL: MariaDB
PROGRAMMING LANGUAGE: Structured Query language (SQL)
THEORY:
1. SQL:
SQL (Structured Query Language) is used in programming and designed for managing
data held in relational database management systems (RDBMS). It is particularly useful
in handling structured data. SQL can execute queries against a database, retrieve data
from a database, insert records into database tables, etc.
DDL is an acronym for Data Definition Language. It consists of SQL commands that can
be used to define database schema.
CREATE - Creates a database or its object.
DROP - To delete objects from the database.
ALTER - To alter the structure of the database.
TRUNCATE - To remove all records from a table.
RENAME - To rename an object existing in the database.
DML is an acronym for Data Manipulation Language. It deals with the manipulation of
the present data in the database.
INSERT - To insert data into a table.
UPDATE - To update existing data within a table.
DELETE - To delete records from a database table.
1
OPERATIONS EXECUTED:
Create Database: create database database_name;
1. Create Database: create database database_name;
2. Use Database: use database_name;
3. Show Databases: show databases;
4. Drop database: drop database database_name;
5. Create Table: create table table_name (colm 1 datatype, colm 2 datatype);
6. Describe Table: desc table_name or describe table_name;
7. Show create table table_name;
8. Insert into Table (2 formats)
9. Insert Null values in table
10. Select queries (with and without * )
11. Select Null values from table : is NULL in where clause
12. Alter table (Add Column): alter table table_name add column_name datatype;
13. Alter table (Drop Column): alter table table_name drop column_name;
14. Alter table (Change Column’s data type): alter table table_name modify
column_name new_datatype;
15. Alter table (Change Column’s name): alter table table_name change
old_column_name new_column_name datatype_to_be_assigned;
16. Update: update table_name set column_name = value where…;
17. Delete: delete from table_name where column_name = value;
18. Truncate: truncate table_name;
19. Rename table: rename table old_table_name to new_table_name;
20. Drop: drop table
table_name; (Use of upward
arrow key)
2
OUTPUT:
Setting environment for MariaDB 10.8 (x64)
C:\WINDOWS\System32>mysql -u root -p
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Database changed
+ +
| Database |
+ +
| animals |
| database_name |
| database_select |
| information_schema |
| mysql |
| performance_schema |
| ishita |
| sys |
3
| vjti |
+ +
+ +
| Database |
+ +
| animals |
| birds |
| database_name |
| database_select |
| information_schema |
| mysql |
| performance_schema |
| ishita |
| sys |
| vjti |
+ +
+ +
4
| Database |
+ +
| animals |
| database_name |
| database_select |
| information_schema |
| mysql |
| performance_schema |
| sakshi |
| sys |
| vjti |
+ +
MariaDB [animals]> CREATE TABLE Animals(name VARCHAR(50), type VARCHAR(50), age INT);
+ + + + + + +
+ + + + + + +
+ + + + + + +
5
+ + -
+
+ + -
+
+ + -
+
+ + + +
+ + + +
| Shelby | Dog | 2 |
| Skitu | Cat | 4 |
+ + + +
6
MariaDB [animals]> INSERT INTO Animals()VALUES();
+ + + +
+ + + +
| Shelby | Dog | 2 |
| Skitu | Cat | 4 |
| Alex | NULL | 3 |
+ + + +
+ + +
| name | age |
+ + +
| Shelby | 2 |
| Skitu | 4 |
| Alex | 3 |
| NULL | NULL |
+ + +
+ + + +
7
+ + + +
| Alex | NULL | 3 |
+ + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
8
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
9
| NULL | NULL | NULL | NULL | NULL |
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
10
MariaDB [animals]> DELETE FROM Animals WHERE name = 'Alex';
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
11
MariaDB [animals]> SHOW TABLES;
+ +
| Tables_in_animals |
+ +
| types_of_animals |
+ +
SNAPSHOTS OF CODE:
12
13
14
15
16
17
18
CONCLUSION:
We have studied and executed various DDL and DML operations on database tables using
SQL. Operations like CREATE, INSERT, UPDATE, DELETE, ALTER, etc. are executed in the
above code.
19