Database Management System
Database Management System
1. Primary Key – A primary key is a field or column that uniquely identifies the
each record.
2. Composite Primary Key – Composite primary key is a key of two or more
attributes that uniquely identifies the row.
3. Foreign Key – A foreign key is a field or a set of fields in a table that refers to
the primary key of another table.
4. Alternate Key – An alternate key is a candidate key that is not chosen to be the
primary key.
5. Candidate Key – A candidate key is a unique key that can be used as a primary
key.
SQL (Structured Query Language)
SQL (Structured Query Language) is the language used in RDBMS for writing queries.
Using SQL, a user can create queries to fetch and manipulate the data of the
database.
The SQL commands are of two types (according to syllabus):
1. Data Definition Language (DDL)
2. Data Manipulation Language (DML)
Data Definition Language (DDL)
These commands are used to define and modify the structure of a database. The
commands that fall under this category are listed as follows:
1. CREATE – It is used to create a new database or table.
CREATE TABLE
SYNTAX: CREATE TABLE table_name(column_definition1,
column_definition2, ........ ,........);
EXAMPLE: CREATE TABLE employee(e_id int(8), e_name char(30));
Que: Write a command and query to create the structure of a table named
“student1”.
Ans: CREATE TABLE Student1 (Roll_No INT, Class CHAR, Name CHAR, Marks INT);
2. ALTER – It is used to modify the structure of an existing database or table.
TO ADD COLUMN (FIELD)
SYNTAX: ALTER TABLE <Table_Name> ADD COLUMN <Column_Name> <Data_Type>;
EXAMPLE: ALTER TABLE employee ADD COLUMN e_loc char(50);
TO REMOVE/DROP COLUMN (FIELD)
SYNTAX: ALTER TABLE <Table_Name> DROP COLUMN <Column_Name>;
EXAMPLE: ALTER TABLE employee DROP COLUMN e_loc;
3. DROP – Deletes an existing database or table.
TO DROP TABLE
SYNTAX: DROP TABLE <Table_Name>;
EXAMPLE: DROP TABLE employee;
TO DROP DATABASE
SYNTAX: DROP DATABASE <Database_Name>;
EXAMPLE: DROP DATABASE myschool_db;
4. TRUNCATE – Remove all table records including allocated table spaces, but not the
table itself.
SYNTAX: TRUNCATE TABLE <Table_Name>;
EXAMPLE: TRUNCATE TABLE employee;
5. RENAME – It is used to change the name of existing database or table.
SYNTAX: ALTER TABLE <Table_Name> RENAME TO <New_Table_Name>;
EXAMPLE: ALTER TABLE employee RENAME TO customers;
Data Manipulation Language (DML)
A DML (Data Manipulation Language) is a computer programming language used for
adding (inserting), modifying (updating) and data in database. The commands that fall
under this category are listed as follows:
1. INSERT – The insert command is used to add one or more records to a table. There
are two methods to use the INSERT command.
Method 1:
SYNTAX: INSERT INTO <Table_Name> (Field 1, Field 2,….) VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee (‘e_id’, ‘e_name’,) VALUES (1, “Mukesh”);
Method 2:
SYNTAX: INSERT INTO <Table_Name> VALUES (Value 1, Value 2,….);
EXAMPLE: INSERT INTO employee VALUES (1, “Mukesh”);
2. SELECT – It is used to retrieves or fetch the data from the table.
TO FETCH ENTIRE RECORD OF TABLE [* means ALL records]
SYNTAX: SELECT * FROM <Table_Name>;
EXAMPLE: SELECT * FROM employee;
TO FETCH RECORD OF SELECTED FIELDS FROM TABLE
SYNTAX: SELECT <Field1, Field2,…> FROM <Table_Name>;
EXAMPLE: SELECT e_name, e_id FROM <Table_Name>;