0% found this document useful (0 votes)
96 views11 pages

DBMS Part 2

The document discusses database concepts like tables, rows, columns, primary keys, foreign keys, and SQL statements. It provides examples of how to: 1) Create a database and table using SQL commands like CREATE DATABASE and CREATE TABLE. 2) Manipulate data using SQL statements such as SELECT, INSERT, UPDATE, and DELETE. 3) Add, modify and drop columns from a table using ALTER TABLE commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views11 pages

DBMS Part 2

The document discusses database concepts like tables, rows, columns, primary keys, foreign keys, and SQL statements. It provides examples of how to: 1) Create a database and table using SQL commands like CREATE DATABASE and CREATE TABLE. 2) Manipulate data using SQL statements such as SELECT, INSERT, UPDATE, and DELETE. 3) Add, modify and drop columns from a table using ALTER TABLE commands.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

VELAMMAL VIDYALAYA,

X – INFORMATION TECHNOLOGY (402)


DATABASE MANAGEMENT SYSTEM

Columns or Fields
A column is a set of data values of a particular simple type
Rows or Records or Tuples
A row also called a record or tuple represents a single, data item in a table.

A database table can be visualized as consisting of rows and columns or fields. Each row
in a table represents a set of related data, and every row in the table has the same
structure.

Data types in OpenOffice base


• Numeric Types
• Alphanumeric Types
• Binary Types
• Date time
• Other Variable types

Numeric Types - Used for describing numeric values for the field
Alphanumeric datatype

Binary datatype – Used for storing image, sound or audio files

Date and

Time - used for describing date and time values for the field

PRIMARY KEY
The PRIMARY KEY uniquely identifies a record in a table.
Primary keys must contain
● UNIQUE values
● cannot contain NULL values
■ A table can have only ONE primary key; and in the table
■ primary key can consist of single or multiple columns (fields).
■ multiple columns (fields) are used they are called a composite key
Delete Primary Key

You can clear the primary key constraints from the table with the syntax given below.

ALTER TABLE CUSTOMERS DROP PRIMARY KEY ;

FOREIGN KEY

It is a key used to link two tables together.

A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY
KEY in another table.
The table containing the foreign key is called the child table, and the table containing the
candidate key is called the referenced or parent table.
Example:

"Persons" table:
PersonI LastNam FirstNam
Age
D e e
1 Hansen Ola 30
2 Svendson Tove 23
3 Pettersen Kari 20
"Orders" table:
OrderNumbe PersonI
OrderID
r D
1 77895 3
2 44678 3
3 22456 2
4 24562 1
Notice that the "PersonID" column in the "Orders" table points to the "PersonID" column
in the "Persons" table.
The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons" table.
The "PersonID" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
The FOREIGN KEY constraint is used to prevent actions that would destroy links between
tables.
The FOREIGN KEY constraint also prevents invalid data from being inserted into the
foreign key column, because it has to be one of the values contained in the table it points
to.

MANIPULATING DATA
◆ Data Definition Language (DDL)
◆ Data Manipulation Language (DML)

Data Definition Language (DDL) or Data Description Language (DDL)


● define the different structures in a database
● DDL statements create, modify, and remove database
● Common DDL statements are CREATE, ALTER, and DROP.

SQL CREATE DATABASE statement


used to create a new SQL database.

Syntax

CREATE DATABASE DatabaseName;


Example:
CREATE DATABASE testDB;

SQL DROP DATABASE statement


used to drop an existing database

Syntax

DROP DATABASE DatabaseName;


Example:
DROP DATABASE testDB;

SQL ALTER DATABASE statement

ALTER command is used to add, delete or modify columns in an existing table.

Syntax

The basic syntax of an ALTER TABLE command to add a New Column in an existing table
is as follows.

ALTER TABLE table_name ADD column_name datatype;

The basic syntax of an ALTER TABLE command to DROP COLUMN in an existing table is
as follows.

ALTER TABLE table_name DROP COLUMN column_name;


The basic syntax of an ALTER TABLE command to change the DATA TYPE of a column in
a table is as follows.

ALTER TABLE table_name MODIFY COLUMN column_name datatype;

Data Manipulation Language (DML)


● enables users to access and manipulate data in a database
● The terms DML and query language are often used synonymously
● Data manipulation involves:
• Retrieval of information from the database- SELECT statement
• Insertion of new information into the database - INSERT statement
• Deletion of information in the database - DELETE statement
• Modification of information in the database - UPDATE statement

SQL SELECT statement

Syntax

SELECT column1, column2, columnN FROM table_name;

SELECT * FROM table_name;


Example:
SELECT ID, NAME, SALARY FROM CUSTOMERS;
SQL WHERE clause
● Used to specify a condition while fetching the data from a single table or by joining
with multiple tables.
● If the given condition is satisfied, then only it returns a specific value from the
table.
● You should use the WHERE clause to filter the records and fetching only the
necessary records.
● The WHERE clause is not only used in the SELECT statement, but it is also used in
the UPDATE, DELETE statement, etc.,
Syntax

SELECT column1, column2, columnN FROM table_name WHERE [condition]

You can specify a condition using the comparison or logical operators like >, <, =,LIKE,
NOT, etc.
Example:
SELECT ID, NAME, SALARY FROM CUSTOMERS WHERE SALARY > 2000;

SQL UPDATE Query


used to modify the existing records in a table.
WHERE clause is used with UPDATE query to update the selected rows, otherwise all the
rows would be affected.
Syntax
UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition]

INSERT INTO Statement


used to add new rows of data to a table in the database.

INSERT INTO TABLE_NAME (column1, column2, column3,...columnN)VALUES (value1,


value2, value3,...valueN);
or
INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);
SQL DELETE Query

● used to delete the existing records from a table.

● use the WHERE clause with a DELETE query to delete the selected rows, otherwise
all the records would be deleted.

DELETE FROM table_name WHERE [condition];

DELETE FROM CUSTOMERS WHERE ID = 6;

+----+----------+-----+-----------+----------+

| ID | NAME | AGE | ADDRESS | SALARY |


+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+

CREATING A DATABASE OBJECT


Start → Programs → OpenOffice.org 6.4 → OpenOffice.org Base
● Create Database
CREATING A TABLE

Click on Create Table in Design View


BUILDING FORMS

You might also like