0% found this document useful (0 votes)
8 views7 pages

Table

The document explains the structure and function of tables in databases, highlighting their organization in rows and columns for data storage and retrieval. It covers SQL commands for creating, dropping, and deleting tables, as well as the concept of Entity Relationship Diagrams (ERD) which illustrate the relationships between entities in a database. Additionally, it defines entities, attributes, and relationships, including the distinction between strong and weak entities.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Table

The document explains the structure and function of tables in databases, highlighting their organization in rows and columns for data storage and retrieval. It covers SQL commands for creating, dropping, and deleting tables, as well as the concept of Entity Relationship Diagrams (ERD) which illustrate the relationships between entities in a database. Additionally, it defines entities, attributes, and relationships, including the distinction between strong and weak entities.

Uploaded by

laita nikam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

A table is an arrangement of information in rows and columns containing cells that make comparing

and contrasting information easier. As you can see in the following example, the data is easier to read
in a table format.

Example table in HTML

Name Date of Birth Phone

Bob Smith 01-05-65 555-123-4567

Joe Smith 09-10-79 555-801-9876

Jane Doe 07-20-70 555-232-1818

Example of the same data in a list

Name,Date of Birth,Phone

Bob Smith,01-05-65,555-123-4567

Joe Smith, 09-10-79,555-801-9876

Jane Doe,07-20-70,555-232-1818

Tables in a database

In a database, a table consists of columns and rows of data, much like an Excel spreadsheet. It is often
referenced by software programs and web pages, to store and retrieve data for users. There are
multiple types of databases, but the structure of a table in each database type is mostly the same.

SQL Table

o SQL Table is a collection of data which is organized in terms of rows and columns. In DBMS, the
table is known as relation and row as a tuple.

o Table is a simple form of data storage. A table is also considered as a convenient representation
of relations.

Let's see an example of the EMPLOYEE table:

EMP_ID EMP_NAME CITY PHONE_NO

1 Kristen Washington 7289201223

2 Anna Franklin 9378282882

3 Jackson Bristol 9264783838

4 Kellan California 7254728346

5 Ashley Hawaii 9638482678

In the above table, "EMPLOYEE" is the table name, "EMP_ID", "EMP_NAME", "CITY", "PHONE_NO" are the
column names. The combination of data of multiple columns forms a row, e.g., 1, "Kristen",
"Washington" and 7289201223 are the data of one row.

Operation on Table

1. Create table

2. Drop table

3. Delete table

4. Rename table

SQL Create Table

SQL create table is used to create a table in the database. To define the table, you should define the
name of the table and also define its columns and column's data type.

Syntax
1. create table "table_name"

2. ("column1" "data type",

3. "column2" "data type",

4. "column3" "data type",

5. ...

6. "columnN" "data type");

Example

1. SQL> CREATE TABLE EMPLOYEE (

2. EMP_ID INT NOT NULL,

3. EMP_NAME VARCHAR (25) NOT NULL,

4. PHONE_NO INT NOT NULL,

5. ADDRESS CHAR (30),

6. PRIMARY KEY (ID)

7. );

If you create the table successfully, you can verify the table by looking at the message by the SQL
server. Else you can use DESC command as follows:

SQL> DESC EMPLOYEE;

Field Type Null Key Default Extra

EMP_ID int(11) NO PRI NULL

EMP_NAME varchar(25) NO NULL

PHONE_NO NO int(11) NULL

ADDRESS YES NULL char(30)

o 4 rows in set (0.35 sec)

Now you have an EMPLOYEE table in the database, and you can use the stored information related to
the employees.

Drop table

A SQL drop table is used to delete a table definition and all the data from a table. When this command
is executed, all the information available in the table is lost forever, so you have to very careful while
using this command.

Syntax

1. DROP TABLE "table_name";

Firstly, you need to verify the EMPLOYEE table using the following command:

1. SQL> DESC EMPLOYEE;

Field Type Null Key Default Extra

EMP_ID int(11) NO PRI NULL

EMP_NAME varchar(25) NO NULL

PHONE_NO NO int(11) NULL


ADDRESS YES NULL char(30)

This table shows that EMPLOYEE table is available in the database, so we can drop it as follows:

1. SQL>DROP TABLE EMPLOYEE;

Now, we can check whether the table exists or not using the following command:

1. Query OK, 0 rows affected (0.01 sec)

As this shows that the table is dropped, so it doesn't display it.

SQL DELETE table

In SQL, DELETE statement is used to delete rows from a table. We can use WHERE condition to delete a
specific row from a table. If you want to delete all the records from the table, then you don't need to
use the WHERE clause.

Syntax

1. DELETE FROM table_name WHERE condition;

Example

Suppose, the EMPLOYEE table having the following records:

EMP_ID EMP_NAME CITY PHONE_NO SALARY

1 Kristen Chicago 9737287378 150000

2 Russell Austin 9262738271 200000

3 Denzel Boston 7353662627 100000

4 Angelina Denver 9232673822 600000

5 Robert Washington 9367238263 350000

6 Christian Los angels 7253847382 260000

The following query will DELETE an employee whose ID is 2.

1. SQL> DELETE FROM EMPLOYEE

2. WHERE EMP_ID = 3;

Now, the EMPLOYEE table would have the following records.

EMP_ID EMP_NAME CITY PHONE_NO SALARY

1 Kristen Chicago 9737287378 150000

2 Russell Austin 9262738271 200000

4 Angelina Denver 9232673822 600000

5 Robert Washington 9367238263 350000

6 Christian Los angels 7253847382 260000

If you don't specify the WHERE condition, it will remove all the rows from the table.

1. DELETE FROM EMPLOYEE;

Now, the EMPLOYEE table would not have any records.

Entity Relationship Diagram (ERD)

An Entity Relationship Diagram (ERD) is a snapshot of data structures. An Entity Relationship Diagram
shows entities (tables) in a database and relationships between tables within that database. For a good
database design it is essential to have an Entity Relationship Diagram.
There are three basic elements in ER-Diagrams:

 Entities are the "things" for which we want to store information. An entity is a person, place,
thing or event.

 Attributes are the data we want to collect for an entitiy.

 Relationships describe the relations between the entities.

Following are the main components and its symbols in ER Diagrams:

 Rectangles: This Entity Relationship Diagram symbol represents entity types

 Ellipses : Symbol represent attributes

 Diamonds: This symbol represents relationship types

 Lines: It links attributes to entity types and entity types with other relationship types

 Primary key: attributes are underlined

 Double Ellipses: Represent multi-valued attributes


ER Diagram Symbols

Components of the ER Diagram

This model is based on three basic concepts:

 Entities

 Attributes

 Relationships

ER Diagram Examples

For example, in a University database, we might have entities for Students, Courses, and
Lecturers. Students entity can have attributes like Rollno, Name, and DeptID. They might
have relationships with Courses and Lecturers.
WHAT IS ENTITY?

A real-world thing either living or non-living that is easily recognizable and nonrecognizable. It is
anything in the enterprise that is to be represented in our database. It may be a physical thing or
simply a fact about the enterprise or an event that happens in the real world.

An entity can be place, person, object, event or a concept, which stores data in the database. The
characteristics of entities are must have an attribute, and a unique key. Every entity is made up of
some 'attributes' which represent that entity.

Examples of entities:

 Person: Employee, Student, Patient

 Place: Store, Building

 Object: Machine, product, and Car

 Event: Sale, Registration, Renewal

 Concept: Account, Course

Notation of an Entity

Entity set:

Student

An entity set is a group of similar kind of entities. It may contain entities with attribute sharing similar
values. Entities are represented by their properties, which also called attributes. All attributes have
their separate values. For example, a student entity may have a name, age, class, as attributes.

Example of Entities:

A university may have some departments. All these departments employ various lecturers and offer
several programs.

Some courses make up each program. Students register in a particular program and enroll in various
courses. A lecturer from the specific department takes each course, and each lecturer teaches a
various group of students.

Relationship

Relationship is nothing but an association among two or more entities. E.g., Tom works in the
Chemistry department.

Entities take part in relationships. We can often identify relationships with verbs or verb phrases.

For example:

 You are attending this lecture

 I am giving the lecture

 Just loke entities, we can classify relationships according to relationship-types:


 A student attends a lecture

 A lecturer is giving a lecture.

Weak Entities

A weak entity is a type of entity which doesn't have its key attribute. It can be identified uniquely by
considering the primary key of another entity. For that, weak entity sets need to have participation.

In above ER Diagram examples, "Trans No" is a discriminator within a group of transactions in an ATM.

Let's learn more about a weak entity by comparing it with a Strong Entity

Strong Entity Set Weak Entity Set

Strong entity set always has a primary key. It does not have enough attributes to build a
primary key.

It is represented by a rectangle symbol. It is represented by a double rectangle symbol.

It contains a Primary key represented by the It contains a Partial Key which is represented by
underline symbol. a dashed underline symbol.

The member of a strong entity set is called as The member of a weak entity set called as a
dominant entity set. subordinate entity set.

Primary Key is one of its attributes which helps to In a weak entity set, it is a combination of
identify its member. primary key and partial key of the strong entity
set.

In the ER diagram the relationship between two The relationship between one strong and a weak
strong entity set shown by using a diamond entity set shown by using the double diamond
symbol. symbol.

The connecting line of the strong entity set with The line connecting the weak entity set for
the relationship is single. identifying relationship is double.

Attributes

It is a single-valued property of either an entity-type or a relationship-type.

For example, a lecture might have attributes: time, date, duration, place, etc.

An attribute in ER Diagram examples, is represented by an Ellipse

You might also like