SlideShare une entreprise Scribd logo
1  sur  25
Rushdi Shams, Dept of CSE, KUET 1
Database SystemsDatabase Systems
TablesTables
Data TypesData Types
Version 1.0Version 1.0
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
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
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
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
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
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)
8Rushdi Shams, Dept of CSE, KUET
Characteristics of a TableCharacteristics of a Table
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
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)
););
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)
););
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)
););
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)
););
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
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.
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!
17Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
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
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
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
21Rushdi Shams, Dept of CSE, KUET
Simple Data Types (continued)Simple Data Types (continued)
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! 
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
24Rushdi Shams, Dept of CSE, KUET
Data Dictionary (continued)Data Dictionary (continued)
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

Contenu connexe

Similaire à Database Tables and Data Types

Similaire à Database Tables and Data Types (20)

Sql
SqlSql
Sql
 
Database Keys / Referential Integrity / Propagation Constraint / Entity Integ...
Database Keys / Referential Integrity / Propagation Constraint / Entity Integ...Database Keys / Referential Integrity / Propagation Constraint / Entity Integ...
Database Keys / Referential Integrity / Propagation Constraint / Entity Integ...
 
Physical elements of data
Physical elements of dataPhysical elements of data
Physical elements of data
 
Database
DatabaseDatabase
Database
 
Lec 11. One Dimensional Arrays
Lec 11. One Dimensional ArraysLec 11. One Dimensional Arrays
Lec 11. One Dimensional Arrays
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
2017 biological databasespart2
2017 biological databasespart22017 biological databasespart2
2017 biological databasespart2
 
Intro to tsql unit 1
Intro to tsql   unit 1Intro to tsql   unit 1
Intro to tsql unit 1
 
Ankit
AnkitAnkit
Ankit
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
Create table
Create tableCreate table
Create table
 
2016 02 23_biological_databases_part2
2016 02 23_biological_databases_part22016 02 23_biological_databases_part2
2016 02 23_biological_databases_part2
 
Sql server ___________session_15(data integrity)
Sql server  ___________session_15(data integrity)Sql server  ___________session_15(data integrity)
Sql server ___________session_15(data integrity)
 
SQL
SQLSQL
SQL
 
Access 2010
Access 2010Access 2010
Access 2010
 
2019 02 21_biological_databases_part2_v_upload
2019 02 21_biological_databases_part2_v_upload2019 02 21_biological_databases_part2_v_upload
2019 02 21_biological_databases_part2_v_upload
 
SImple SQL
SImple SQLSImple SQL
SImple SQL
 
Advanced SQL Webinar
Advanced SQL WebinarAdvanced SQL Webinar
Advanced SQL Webinar
 
Quick And Dirty Databases
Quick And Dirty DatabasesQuick And Dirty Databases
Quick And Dirty Databases
 

Plus de Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

Plus de Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Dernier

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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