You are on page 1of 4

Creating a database in mariadb prompt of Xampp server:

1. Start xampp control panel and start apache and mysql servers. Minimize this
window.

2. Open the windows command prompt

3. Change the directory to C:\Xampp\mysql\bin

4. Type the command mysql.exe -u root <space> ( after root leave a space for
password)

5. the prompt will be changed to mariadb(none)>: This shows that no database


is selected.

Important commands related to database:

1. Creating a database: create database <database_name>

MariaDB [(none)]> create database univ;

2. Viewing the existing databases: show databases;

3. To select any database: use <database_name>

MariaDB [(none)]> use univ;

4. To display the created in the database: show tables;


DDL

1. Create
1. Create
2. Create table as
2. Alter
1. Add (single column/ multiple column)
2. Add (After)
3. Modify(single column/multiple column)
4. Drop(column)
5. Change Column Name
6. Rename table
3. Drop
1. Drop (single table/multiple table/ temporary table)

1. Create

Syntax

CREATE TABLE table_name( column1 datatype [ NULL | NOT NULL ],column2


datatype [ NULL | NOT NULL ]);

Eg

Create table student(name varchar(20), regno integer(8), dob date);

CREATE TABLE AS

Syntax

CREATE TABLE new_table [ AS ] SELECT expressions FROM existing_tables


[WHERE conditions];

Eg

Create table stud as (select * from student);


2. Alter

Add (single column)

syntax

ALTER TABLE table_name ADD new_column_name column_definition [ FIRST |


AFTER column_name ];

Eg

Alter table student add age integer(3);

Add (multiple column)

syntax

ALTER TABLE table_name ADD new_column_name column_definition [ FIRST |


AFTER column_name ], ADD new_column_name column_definition[ FIRST |
AFTER column_name ];

Eg

ALTER TABLE student ADD last_name varchar(40) NOT NULL AFTER sid, ADD
address varchar(35) NULL AFTER last_name;

Add using after

Syntax

ALTER TABLE table_name ADD new_column_name column_definition [ FIRST |


AFTER column_name ];

Eg

Alter table student add last_name varchar(40) NOT NULL AFTER sid;

Modify

Syntax

ALTER TABLE table_name MODIFY column_name column_definition [ FIRST |


AFTER column_name ];

Eg

Alter table student modify name varchar(30);


Drop

Syntax

ALTER TABLE table_name DROP COLUMN column_name;

Eg

Alter table student drop age;

Change Column Name

Syntax

ALTER TABLE table_name CHANGE COLUMN old_name new_name


column_definition [ FIRST | AFTER column_name ]

Eg

ALTER TABLE student CHANGE COLUMN std_id sid integer(8) NOT NULL;

Rename table

Syntax

ALTER TABLE table_name RENAME TO new_table_name;

Eg

ALTER TABLE student RENAME TO stud;

3. Drop

Syntax

DROP TABLE table_name;

Eg

Drop table student;

Drop Multiple Tables

DROP TABLE customers, suppliers;

Drop Temporary Table

DROP TEMPORARY TABLE IF EXISTS customers;

You might also like