6 - Tables of A Database
6 - Tables of A Database
TABLE OF A
DATABASE
RAYMOND S. BERMUDEZ
Instructor, College of Computer Studies - MSEUF
Table of a database
A table is primarily a list of items or a
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Table Name
To complete the creation of a table, you
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Table Name
Besides these rules, you can make up
act or Second
After the first character as an underscore or
a letter, the name will have combinations of
underscores, letters, and digits. Examples
are _n24, act_52_t
Unless stated otherwise, a name will not
include special characters such as !, @, #, $,
%, ^, &, or *
If the name is a combination of words, each
word will start in uppercase. Examples are
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Data types are the most
fundamental constraint
element of a database in that
it restricts the range of
possible values that are
allowed to be stored within a
column.
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Range of Value
Storage
Space
tinyint
0 to 255
1 byte
smallint
-32,768 to 32,767
2 bytes
int
-231 to 231 -1
4 bytes
bigint
-263 to 263 -1
8 bytes
decimal(p,s)
numeric(p,s)
-1038 to 1038 -1
5 to 17 bytes
smallmoney
-214,748.3648 to 214,748.3647
4 bytes
money
-922,337,203,685,477.5808 to
922,337,203,685,477.5807
8 bytes
real
4 bytes
Float
4 bytes or 8
bytes
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Character data type
char(n) - 1 byte per character
defined by n up to a maximum of
8000 bytes
varchar(n)
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Character data type
text -1 byte per character stored up
to a maximum of 2 GB
nchar(n) -2 bytes per character
defined by n up to a maximum of
4000 bytes
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Character data type
nvarchar(n)- 2 bytes per characters
stored up to a maximum of 4000
bytes
ntext- 2 bytes per character stored
up to a maximum of 2 GB
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Character data type
smalldatetime
01/01/1900
to 06/06/2079
datetime
01/01/1753 to
12/31/9999
date
01/01/0001 to
12/31/9999
time
00:00:00.0000000
to 23:59:59.9999999
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
Data Type
Binary Data
bit
Null, 0 and 1 1 bit
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
values.
A primary key column cannot
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
to delete a table.
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
SQLAUTO
INCREMENTField
Auto-increment allows a unique
SQLAUTO
INCREMENTField
Example
CREATE TABLE Persons
(
P_Id int PRIMARY KEY IDENTITY,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
Note:To specify the column (for example PID)
should start at value 10 and increment by 5,
change the identity to IDENTITY(10,5).
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
BY: Mr. RAYMOND S. BERMUDEZ, - Instructor, College of Computer Studies, MSEUF Lucena City
LESSON 5
TABLE OF A
DATABASE
RAYMOND S. BERMUDEZ
Instructor, College of Computer Studies - MSEUF