Page 1 - DDL and DML Commands
P. 1
Structured Query Language
(DDL & DML)
Creating Database
To create database:
CREATE DATABASE [IF NOT EXISTS] <database name>;
To open database:
USE <database name>;
To show names of all databases:
SHOW databases;
To show name of active database:
SHOW database();
To delete/drop database:
DROP DATABASE <database name>;
Creating Table
Syntax is:
CREATE TABLE <table name>
(<column name> <data type> [<size>] [<column constraint>],
…………………….,
[<table constraint>]
);
Constraints
Constraints restricts the data entry to a column.
Different types are:
1. Not Null
2. Unique
3. Check
4. Primary Key
5. Foreign Key
6. Default
Constraints can be applied on column or table level.
NOT NULL Constraints
Can be applied at column level only.
Values in this field can not be NULL / left blank.
e.g.
create table STUDENT
(admNo integer NOT NULL,
name varchar(50));