How to Troubleshoot Apps for the Modern Connected Worker
Database Tables and Data Types
1. Rushdi Shams, Dept of CSE, KUET 1
Database SystemsDatabase Systems
TablesTables
Data TypesData Types
Version 1.0Version 1.0
2. 2Rushdi Shams, Dept of CSE, KUET
Basics of TableBasics of Table
In a data model, table is a bucket where youIn a data model, table is a bucket where you
pour data.pour data.
Data in a specific table is associated with allData in a specific table is associated with all
other items in that table.other items in that table.
In a table, there are basically 3 things-In a table, there are basically 3 things-
1.1. Rows / Records / TuplesRows / Records / Tuples
2.2. Columns / Attributes / FieldsColumns / Attributes / Fields
3.3. DataData
3. 3Rushdi Shams, Dept of CSE, KUET
Basics of TableBasics of Table
In the table, the column goes on in a horizontalIn the table, the column goes on in a horizontal
fashion.fashion.
ISBN, AUTHOR, PUBLISHER, TITLE, GENRE,ISBN, AUTHOR, PUBLISHER, TITLE, GENRE,
PRINTED are the column names for this tablePRINTED are the column names for this table
4. 4Rushdi Shams, Dept of CSE, KUET
Basics of TableBasics of Table
In the table, the row goes on in a vertical fashion.In the table, the row goes on in a vertical fashion.
Every row in this table has data for ISBN, AUTHOR,Every row in this table has data for ISBN, AUTHOR,
PUBLISHER, TITLE, GENRE, PRINTEDPUBLISHER, TITLE, GENRE, PRINTED
5. 5Rushdi Shams, Dept of CSE, KUET
Basic of TableBasic of Table
Books contain relatively disorganized dataBooks contain relatively disorganized data
Organize information using modelOrganize information using model
Resulting in a neatly structured set of rows and columnsResulting in a neatly structured set of rows and columns
6. 6Rushdi Shams, Dept of CSE, KUET
Relation / TableRelation / Table
In relational data model, the table is also calledIn relational data model, the table is also called
relation. There are set of rules that are applied on therelation. There are set of rules that are applied on the
relations. You must have to know them.relations. You must have to know them.
1.1. A database contains many relations. Every relations inA database contains many relations. Every relations in
a database must have distinct namesa database must have distinct names
2.2. Every column in a relation must have distinct namesEvery column in a relation must have distinct names
3.3. Every entries in a column must be in the same domainEvery entries in a column must be in the same domain
4.4. The ordering of columns in a relation is insignificantThe ordering of columns in a relation is insignificant
7. 7Rushdi Shams, Dept of CSE, KUET
Relation / Table (continued)Relation / Table (continued)
5.5. Duplicate rows are not allowed in a relationDuplicate rows are not allowed in a relation
6.6. The ordering of rows is insignificantThe ordering of rows is insignificant
7.7. Multiple values are not allowed in the cells of aMultiple values are not allowed in the cells of a
relationrelation
8.8. 2 rows in a relation may contain the same2 rows in a relation may contain the same
value for 1 columns but not in all (deviation ofvalue for 1 columns but not in all (deviation of
5)5)
8. 8Rushdi Shams, Dept of CSE, KUET
Characteristics of a TableCharacteristics of a Table
9. 9Rushdi Shams, Dept of CSE, KUET
TerminologyTerminology
The number of rows in a table is calledThe number of rows in a table is called
CardinalityCardinality
The number of columns in a table is calledThe number of columns in a table is called
DegreeDegree
10. 10Rushdi Shams, Dept of CSE, KUET
Creating TableCreating Table
This SQL command willThis SQL command will
create a table named Studentcreate a table named Student
Student will have 6Student will have 6
columns-columns-
1.1. IDID
2.2. NameName
3.3. AddressAddress
4.4. Date_of_BirthDate_of_Birth
5.5. YearYear
6.6. SemesterSemester
CREATE TABLE Student (CREATE TABLE Student (
IDID VARCHAR(10)VARCHAR(10) NOTNOT
NULL,NULL,
NameName VARCHAR(20),VARCHAR(20),
AddressAddress VARCHAR(20),VARCHAR(20),
Date_of_BirthDate_of_Birth DATE,DATE,
YearYear INTEGER(1),INTEGER(1),
SemesterSemester INTEGER(1)INTEGER(1)
););
11. 11Rushdi Shams, Dept of CSE, KUET
Creating Table (continued)Creating Table (continued)
Each of the column hasEach of the column has
a definite Data Type.a definite Data Type.
Different vendors ofDifferent vendors of
DBMS have differentDBMS have different
data types.data types.
In choosing themIn choosing them
appropriately, you willappropriately, you will
have to go through theirhave to go through their
documentations! Theydocumentations! They
are huge!are huge!
CREATE TABLE StudentCREATE TABLE Student
((
IDID VARCHAR(10)VARCHAR(10)
NOT NULL,NOT NULL,
NameName VARCHAR(20),VARCHAR(20),
AddressAddress VARCHAR(20),VARCHAR(20),
Date_of_BirthDate_of_Birth DATE,DATE,
YearYear INTEGER(1),INTEGER(1),
SemesterSemester INTEGER(1)INTEGER(1)
););
12. 12Rushdi Shams, Dept of CSE, KUET
Creating Table (continued)Creating Table (continued)
Each column has someEach column has some
predefined length onpredefined length on
data types.data types.
As in ID, the ID of aAs in ID, the ID of a
student can be withstudent can be with
maximum length of 10maximum length of 10
and so on.and so on.
CREATE TABLE StudentCREATE TABLE Student
((
IDID VARCHAR(10)VARCHAR(10)
NOT NULL,NOT NULL,
NameName VARCHAR(20),VARCHAR(20),
AddressAddress VARCHAR(20),VARCHAR(20),
Date_of_BirthDate_of_Birth DATE,DATE,
YearYear INTEGER(1),INTEGER(1),
SemesterSemester INTEGER(1)INTEGER(1)
););
13. 13Rushdi Shams, Dept of CSE, KUET
Creating Table (continued)Creating Table (continued)
The NOT NULL field is theThe NOT NULL field is the
last thing to know here. Iflast thing to know here. If
you think that any of youryou think that any of your
columns of your tablecolumns of your table
MUST NOT be NULL,MUST NOT be NULL,
then you specify it.then you specify it.
If you don’t specify it,If you don’t specify it,
during inserting data,during inserting data,
anyone may leave thatanyone may leave that
empty. But if you specifyempty. But if you specify
NOT NULL, then theNOT NULL, then the
column MUST have a valuecolumn MUST have a value
for each of its row.for each of its row.
CREATE TABLE Student (CREATE TABLE Student (
IDID VARCHAR(10)VARCHAR(10) NOTNOT
NULL,NULL,
NameName VARCHAR(20),VARCHAR(20),
AddressAddress VARCHAR(20),VARCHAR(20),
Date_of_BirthDate_of_Birth DATE,DATE,
YearYear INTEGER(1),INTEGER(1),
SemesterSemester INTEGER(1)INTEGER(1)
););
14. 14Rushdi Shams, Dept of CSE, KUET
Data TypesData Types
Now, we will plunge into data types for more.Now, we will plunge into data types for more.
Though vendor to vendor data types vary, theyThough vendor to vendor data types vary, they
have some generic types.have some generic types.
1.1. Simple data typesSimple data types
2.2. Complex data typesComplex data types
3.3. Specialized data typesSpecialized data types
15. 15Rushdi Shams, Dept of CSE, KUET
Simple Data TypesSimple Data Types
As the name mentions, they are really simplyAs the name mentions, they are really simply
applied on the data in a tableapplied on the data in a table
Strings:Strings: a string is a sequence of characters. Ita string is a sequence of characters. It
can be fixed length strings and variable lengthcan be fixed length strings and variable length
strings.strings.
16. 16Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
If you limit the number of characters in this kind ofIf you limit the number of characters in this kind of
strings, then it takes exactly the same number ofstrings, then it takes exactly the same number of
characters. CHAR is this type of data type. If you saycharacters. CHAR is this type of data type. If you say
CHAR (3) and put NY there, then it will storeCHAR (3) and put NY there, then it will store
NY<SPACE> in that columnNY<SPACE> in that column
In contrast, a variable length string allows you to putIn contrast, a variable length string allows you to put
data up to a value defined by the user.data up to a value defined by the user.
VARCHAR(10) means this column allows you toVARCHAR(10) means this column allows you to
put 10 characters at mostput 10 characters at most
TEXT (N) is another variable length string!TEXT (N) is another variable length string!
17. 17Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
18. 18Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
Numbers:Numbers: numerical data types. Should Inumerical data types. Should I
say more about them?say more about them?
There are loads of numerical data types-There are loads of numerical data types-
1.1. SMALLINTSMALLINT
2.2. INTEGERINTEGER
3.3. LONGLONG
4.4. FLOATFLOAT
5.5. NUMBERNUMBER
19. 19Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
Fixed length decimals:Fixed length decimals:
Sometimes, you will need to fix theSometimes, you will need to fix the
number of characters in a decimal likenumber of characters in a decimal like
DECIMAL (5,2). From vendor to vendorDECIMAL (5,2). From vendor to vendor
this may differ.this may differ.
With this, it can be like-With this, it can be like-
1.1. It will allow 12345.67 orIt will allow 12345.67 or
2.2. It will allow 123.45It will allow 123.45
20. 20Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
Date and time:Date and time:
Date and time may be formatted asDate and time may be formatted as
follows-follows-
1.1. dd/mm/yyyydd/mm/yyyy
2.2. timstamptimstamp
21. 21Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
22. 22Rushdi Shams, Dept of CSE, KUET
About other data typesAbout other data types
Complex and specialized data types- I will try toComplex and specialized data types- I will try to
discuss them when time will seem appropriatediscuss them when time will seem appropriate
for me!for me!
23. 23Rushdi Shams, Dept of CSE, KUET
Data DictionaryData Dictionary
It is called database designer’s databaseIt is called database designer’s database
During creation of database tables, oftenDuring creation of database tables, often
engineers keep track of their tables by dataengineers keep track of their tables by data
dictionarydictionary
It is not mandatory but recommendedIt is not mandatory but recommended
Contains every possible information about theContains every possible information about the
tables in a databasetables in a database
24. 24Rushdi Shams, Dept of CSE, KUET
Data Dictionary (continued)Data Dictionary (continued)
25. 25Rushdi Shams, Dept of CSE, KUET
ReferenceReference
Beginning Database Design by Gavin Powell,Beginning Database Design by Gavin Powell,
Wrox Publications, 2005Wrox Publications, 2005
Database Systems: Design, ImplementationDatabase Systems: Design, Implementation
& Management by Rob & Coronel, 6& Management by Rob & Coronel, 6thth
EditionEdition