SlideShare a Scribd company logo
Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd
Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn
78
Lession 4: The Tables of a Database
Tables Fundamentals
Introduction
A table is primarily a list of items or a group of lists. To manage such a list, it should be
meticulously organized. To organize this information, it is divided in sections. Here is an
example:
Name Age Gender Relationship
Judie 18 Female Sister
Ernest 24 Male Cousin
Bill 52 Unknown Uncle
David 36 Male Brother
Hermine 12 Unknown Niece
Based on this, a list is simply an arrangement of information and this information, also
called data, is stored in tables.
Visual Creation of a Table
The information of a table is organized in categories called columns and horizontal
arrangements called records or rows. A column holds a category of data that is common
to all records. A table must have at least one column. This means that you cannot create
a table without defining at least one column.
Tables Names
To complete the creation of a table, you must save it. If you are freshly creating a table
and decide to save it, you would be prompted to name it. The name of a table:
Can be made of digits only. For example you can have a table called 148
Can start with a digit, a letter, or an underscore
Can be made of letters, digits, and spaces
Besides these rules, you can make up yours. To avoid confusion, here are the rules we
will use to name our tables:
A name will start with a letter. Examples are 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 Staff Members or Video Titles
Creating a Table With SQL
Introduction
Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd
Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn
79
To assist you with creating a table, you use a Data Definition Language (DDL) command
that is CREATE TABLE, followed by a name. Therefore, to create a table, you start with
the following statement:
CREATE TABLE TableName;
The CREATE TABLE expression is required. The TableName factor specifies the name of
the new table. The TableName can use the rules and suggestions we reviewed for the
tables.
After specifying the name of the table, you must create at least one category, called a
column of data.
Temporary Tables
After creating a table, it becomes part of its database and you can use that table over and
over again. In some cases, you may want to create a table to test something and you
would not need to use that table the next time you connect to the server. Such a table is
referred to as a temporary table.
To create a temporary table, start its name with #, followed by the desired name. Once
the table has been created, it would be available as long as you are using the same
connection to the server. If you close Microsoft SQL Server, the table would be
automatically deleted.
Using Sample Code
To assist you with creating a table, Microsoft SQL Server can generate sample code for
you. You can then simply modify or customize it. First display or open an empty query
window. To display the Templates Explorer, on the main menu, you can click View ->
Templates Explorer. In the Templates Explorer, expand the Table node. Under table, drag
Create Table and drop it in the query window. Sample code would be generated for you.
Tables Maintenance
Introduction
Table maintenance consists of reviewing or changing its aspects. This includes reviewing
the list of tables of a database, renaming a table, or deleting it.
Viewing the Properties of a Table
Like every other object of a database or of the computer, a table possesses some
characteristics that are proper to it. To view these characteristics, in the Object Explorer,
right-click the table and click Properties.
Opening a Table
Most operations require that you open a table before using it. There are various ways a
table displays, depending on how you want to examine it:
To view the structure of a table, perhaps to change its columns, in the Object
Explorer, expand your database and its Tables node. Right-click the table and click
Modify. The table would open in design view, the same view you use to visually
create a table.
Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd
Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn
80
If you want to view the SQL code of a table, in the Object Explorer, right-click the
table, position the mouse on Script Table AS, CREATE To, and click New Query Editor
Window
To open a table to view its data, perhaps to perform data entry, in the Object
Explorer, right-click the table and click Open Table
Tables Review
To see the list of tables of a database in the Object Explorer, you can click the Tables
node:
To see the list of tables of a database using SQL, in a Query window, specify the database
(using a USEstatement), and execute sp_help (it is a stored procedure). Here is an
example:
Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd
Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn
81
Renaming a Table
If you find out that the name of a table is not appropriate, you can change it. To change
the name of a table in the SQL Server Management Studio, in the Object Explorer, right-
click the table and click Rename. Type the desired name and press Enter.
To change the name of a table with code, execute sp_rename, followed by the current
name of the table, a comma, and the new desired name of the table. The formula to use
is:
sp_rename ExistingTableName, TableNewName;
The names of tables should be included in single-quotes. Here is an example:
sp_rename N'StaffMembers', N'Employees';
GO
In this case, the interpreter would look for a table named StaffMembers in the current or
selected database. If it finds it, it would rename it Employees. If the table doesn't exist,
you would receive an error.
Deleting a Table
If you have an undesired table in a database, you can remove it. To delete a table in the
SQL Server Management Studio, in the Object Explorer, right-click the table under its
database node and click Delete. You will receive a warning giving you a chance to confirm
your intentions. If you still want to remove the table, click OK.
To delete a table using SQL, use the following formula:
DROP TABLE TableName
The DROP TABLE expression is required and it is followed by the name of the undesired
table. When you execute the statement, you will not receive a warning before the table is
deleted.
Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd
Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn
82
You can also use sample code that Microsoft SQL Server can generate for you. First
display an empty query window. Also display the Templates Explorer and expand the
Table node. Under Table, drag Drop Table and drop it in the empty query window. Sample
code would be generated for you. You can then simply modify it and execute the
statement.
Referring to a Table
In future lessons, we will write various expressions that involve the names of tables. In
those expressions, you will need to specify a particular table you want to use. There are
three main ways you can do this. To refer to, or to indicate, a table:
You can simply type its name. An example would be Students
You can type dbo, followed by the period operator, followed by the name of the
table. An example would be dbo.Students
You can type the name of the database to which the table belongs, followed by the
period operator, followed by dbo, followed by the period operator, and followed by
the name of the table. An example would be RedOakHighSchool.dbo.Students
Tables and Permissions
The table as an object doesn't have many own rights. Its permissions are controlled partly
by its database owner and by its contents. The primary right to exercise on a database is
the ability to create a table. To visually allow or deny this, access the Database Properties
of the database that owns the table. In the Select a Page list, click Permissions. In the
Users or Roles list, select the user. In the Permissions list, locater the Create Table row:
After granting or denying access, click OK.
To programmatically allow a user to create tables on a database, type GRANT CREATE
TABLE TO followed by the name of the user. Here is an example:
USE Exercise1;
GO
GRANT CREATE TABLE TO [Raymond Kouma];
Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd
Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn
83
GO

More Related Content

What's hot

sorting and filtering data in excel
sorting and filtering data in excelsorting and filtering data in excel
sorting and filtering data in excel
aroosa zaidi
 
Access Reports for Tenderfeet (or is that tenderfoots?)
Access Reports for Tenderfeet (or is that tenderfoots?) Access Reports for Tenderfeet (or is that tenderfoots?)
Access Reports for Tenderfeet (or is that tenderfoots?)
Alan Manifold
 
Frames tables forms
Frames tables formsFrames tables forms
Frames tables forms
nobel mujuji
 
Spss intro for engineering
Spss intro for engineeringSpss intro for engineering
Spss intro for engineering
Mahendra Poudel
 
Access 2007 Training
Access 2007 TrainingAccess 2007 Training
Access 2007 Training
pparakh
 
Spss course session-II
Spss course session-IISpss course session-II
Spss course session-II
altleo
 
SPSS Getting Started Tutorial
SPSS Getting Started TutorialSPSS Getting Started Tutorial
SPSS Getting Started Tutorial
aswhite
 
SPSS introduction Presentation
SPSS introduction Presentation SPSS introduction Presentation
SPSS introduction Presentation
befikra
 
Overview spss student
Overview spss studentOverview spss student
Overview spss student
aswhite
 
اىفناىنمفبانفيا
اىفناىنمفبانفيااىفناىنمفبانفيا
اىفناىنمفبانفيا
Bisan Rjoub
 
Ms excel
Ms excelMs excel
Sql
SqlSql
SQL_Part1
SQL_Part1SQL_Part1
SQL_Part1
Rick Perry
 
CIS145 Final Review
CIS145 Final ReviewCIS145 Final Review
Web forms and html lecture Number 3
Web forms and html lecture Number 3Web forms and html lecture Number 3
Web forms and html lecture Number 3
Mudasir Syed
 
Model Assistant Suite
Model Assistant SuiteModel Assistant Suite
Model Assistant Suite
Ysrael Mertz
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
club23
 
Defining Data in IBM SPSS Statistics
Defining Data in IBM SPSS StatisticsDefining Data in IBM SPSS Statistics
Defining Data in IBM SPSS Statistics
Thiyagu K
 
Introduction to spss 18
Introduction to spss 18Introduction to spss 18
Introduction to spss 18
mbrez
 
MS Access 2010 tutorial 5
MS Access 2010 tutorial 5MS Access 2010 tutorial 5
MS Access 2010 tutorial 5
Khalfan Alshuaili
 

What's hot (20)

sorting and filtering data in excel
sorting and filtering data in excelsorting and filtering data in excel
sorting and filtering data in excel
 
Access Reports for Tenderfeet (or is that tenderfoots?)
Access Reports for Tenderfeet (or is that tenderfoots?) Access Reports for Tenderfeet (or is that tenderfoots?)
Access Reports for Tenderfeet (or is that tenderfoots?)
 
Frames tables forms
Frames tables formsFrames tables forms
Frames tables forms
 
Spss intro for engineering
Spss intro for engineeringSpss intro for engineering
Spss intro for engineering
 
Access 2007 Training
Access 2007 TrainingAccess 2007 Training
Access 2007 Training
 
Spss course session-II
Spss course session-IISpss course session-II
Spss course session-II
 
SPSS Getting Started Tutorial
SPSS Getting Started TutorialSPSS Getting Started Tutorial
SPSS Getting Started Tutorial
 
SPSS introduction Presentation
SPSS introduction Presentation SPSS introduction Presentation
SPSS introduction Presentation
 
Overview spss student
Overview spss studentOverview spss student
Overview spss student
 
اىفناىنمفبانفيا
اىفناىنمفبانفيااىفناىنمفبانفيا
اىفناىنمفبانفيا
 
Ms excel
Ms excelMs excel
Ms excel
 
Sql
SqlSql
Sql
 
SQL_Part1
SQL_Part1SQL_Part1
SQL_Part1
 
CIS145 Final Review
CIS145 Final ReviewCIS145 Final Review
CIS145 Final Review
 
Web forms and html lecture Number 3
Web forms and html lecture Number 3Web forms and html lecture Number 3
Web forms and html lecture Number 3
 
Model Assistant Suite
Model Assistant SuiteModel Assistant Suite
Model Assistant Suite
 
Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)Html 5-tables-forms-frames (1)
Html 5-tables-forms-frames (1)
 
Defining Data in IBM SPSS Statistics
Defining Data in IBM SPSS StatisticsDefining Data in IBM SPSS Statistics
Defining Data in IBM SPSS Statistics
 
Introduction to spss 18
Introduction to spss 18Introduction to spss 18
Introduction to spss 18
 
MS Access 2010 tutorial 5
MS Access 2010 tutorial 5MS Access 2010 tutorial 5
MS Access 2010 tutorial 5
 

Viewers also liked

Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...
Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...
Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...
Dr. Ivo Pezzuto
 
Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015
Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015 Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015
Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015
Dr. Ivo Pezzuto
 
Не стареют душой ветераны...
Не стареют душой ветераны...Не стареют душой ветераны...
Не стареют душой ветераны...school44
 
Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)
Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)
Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)
Dr. Ivo Pezzuto
 
Lession 3 introduction to database
Lession 3 introduction to databaseLession 3 introduction to database
Lession 3 introduction to database
Đỗ Đức Hùng
 
Ivo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUE
Ivo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUEIvo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUE
Ivo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUE
Dr. Ivo Pezzuto
 
Lession 7 records maintenance
Lession 7 records maintenanceLession 7 records maintenance
Lession 7 records maintenance
Đỗ Đức Hùng
 
Lession 2 starting with mssqlserver
Lession 2 starting with mssqlserverLession 2 starting with mssqlserver
Lession 2 starting with mssqlserver
Đỗ Đức Hùng
 
Pre production jubel evailuation v2 1
Pre production jubel evailuation v2 1Pre production jubel evailuation v2 1
Pre production jubel evailuation v2 1
jubel123
 
Mobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi LuhurMobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi Luhur
Riza Fahmi
 
Lession 6.introduction to records
Lession 6.introduction to recordsLession 6.introduction to records
Lession 6.introduction to records
Đỗ Đức Hùng
 
Hanh trangviet.ucoz.net giao trinh sql server 2005
Hanh trangviet.ucoz.net giao trinh sql server 2005Hanh trangviet.ucoz.net giao trinh sql server 2005
Hanh trangviet.ucoz.net giao trinh sql server 2005Đỗ Đức Hùng
 
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại viĐề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại viĐỗ Đức Hùng
 
Modelos de desarrollo
Modelos de desarrolloModelos de desarrollo
Modelos de desarrollo
Oscar Sandoval
 

Viewers also liked (16)

Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...
Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...
Ivo Pezzuto - UNITED STATES: IS A SLOWDOWN IN THE OFFING? (The Global Analyst...
 
Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015
Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015 Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015
Ivo Pezzuto - THE GLOBAL ANALYST JUNE 2015
 
Не стареют душой ветераны...
Не стареют душой ветераны...Не стареют душой ветераны...
Не стареют душой ветераны...
 
Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)
Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)
Ivo Pezzuto's Economic and Geopolitical Overview of Mexico (2013)
 
Lession 3 introduction to database
Lession 3 introduction to databaseLession 3 introduction to database
Lession 3 introduction to database
 
Ivo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUE
Ivo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUEIvo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUE
Ivo Pezzuto - THE GLOBAL ANALYST MAGAZINE AUGUST 2015 ISSUE
 
Lession 7 records maintenance
Lession 7 records maintenanceLession 7 records maintenance
Lession 7 records maintenance
 
Lession 2 starting with mssqlserver
Lession 2 starting with mssqlserverLession 2 starting with mssqlserver
Lession 2 starting with mssqlserver
 
Pre production jubel evailuation v2 1
Pre production jubel evailuation v2 1Pre production jubel evailuation v2 1
Pre production jubel evailuation v2 1
 
Mobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi LuhurMobile Programming - Network Universitas Budi Luhur
Mobile Programming - Network Universitas Budi Luhur
 
Lession 6.introduction to records
Lession 6.introduction to recordsLession 6.introduction to records
Lession 6.introduction to records
 
Bai giang he qtdl
Bai giang he qtdlBai giang he qtdl
Bai giang he qtdl
 
Hanh trangviet.ucoz.net giao trinh sql server 2005
Hanh trangviet.ucoz.net giao trinh sql server 2005Hanh trangviet.ucoz.net giao trinh sql server 2005
Hanh trangviet.ucoz.net giao trinh sql server 2005
 
Đề cương xử lý ảnh
Đề cương xử lý ảnhĐề cương xử lý ảnh
Đề cương xử lý ảnh
 
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại viĐề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
Đề Cương ôn tập kiến trúc máy tính và thiết bị ngoại vi
 
Modelos de desarrollo
Modelos de desarrolloModelos de desarrollo
Modelos de desarrollo
 

Similar to Lession 4 the tables of a database

Lession 5 the columns of a table
Lession 5 the columns of a tableLession 5 the columns of a table
Lession 5 the columns of a table
Đỗ Đức Hùng
 
Ms Access
Ms AccessMs Access
Ms Access
itsvineeth209
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
DivyaKS12
 
Pks ms access unit 4_bcomcs
Pks ms access unit 4_bcomcsPks ms access unit 4_bcomcs
Pks ms access unit 4_bcomcs
KALAISELVI P
 
Database as information system
Database as information systemDatabase as information system
Database as information system
KAZEMBETVOnline
 
Priyank Goel PPT.pptx
Priyank Goel PPT.pptxPriyank Goel PPT.pptx
Priyank Goel PPT.pptx
Namangupta562588
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
SuhaniSinha9
 
MS Access and Database Fundamentals
MS Access and Database FundamentalsMS Access and Database Fundamentals
MS Access and Database Fundamentals
Ananda Gupta
 
Module 08 Access & Use Database Application.pptx
Module 08 Access & Use Database Application.pptxModule 08 Access & Use Database Application.pptx
Module 08 Access & Use Database Application.pptx
Esubalew21
 
Master database management for cxc
Master database management for cxcMaster database management for cxc
Master database management for cxc
lenghorne
 
Operate Spreadsheet applications ppt.pptx
Operate Spreadsheet applications ppt.pptxOperate Spreadsheet applications ppt.pptx
Operate Spreadsheet applications ppt.pptx
Esubalew21
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
PetroJoe
 
1. access
1. access1. access
Dbms question
Dbms questionDbms question
Dbms question
Ricky Dky
 
Access2003
Access2003Access2003
Access2003
tanik363
 
Access2003
Access2003Access2003
Access2003
mrh1222
 
10359485
1035948510359485
10359485
kavumo
 
Intro To TSQL - Unit 1
Intro To TSQL - Unit 1Intro To TSQL - Unit 1
Intro To TSQL - Unit 1
iccma
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
Shahrzad Peyman
 
Sorting, Filtering, and Creating Relationships.pptx
Sorting, Filtering, and Creating Relationships.pptxSorting, Filtering, and Creating Relationships.pptx
Sorting, Filtering, and Creating Relationships.pptx
kulmiyealiabdille
 

Similar to Lession 4 the tables of a database (20)

Lession 5 the columns of a table
Lession 5 the columns of a tableLession 5 the columns of a table
Lession 5 the columns of a table
 
Ms Access
Ms AccessMs Access
Ms Access
 
Database models and DBMS languages
Database models and DBMS languagesDatabase models and DBMS languages
Database models and DBMS languages
 
Pks ms access unit 4_bcomcs
Pks ms access unit 4_bcomcsPks ms access unit 4_bcomcs
Pks ms access unit 4_bcomcs
 
Database as information system
Database as information systemDatabase as information system
Database as information system
 
Priyank Goel PPT.pptx
Priyank Goel PPT.pptxPriyank Goel PPT.pptx
Priyank Goel PPT.pptx
 
DBMS LAB M.docx
DBMS LAB M.docxDBMS LAB M.docx
DBMS LAB M.docx
 
MS Access and Database Fundamentals
MS Access and Database FundamentalsMS Access and Database Fundamentals
MS Access and Database Fundamentals
 
Module 08 Access & Use Database Application.pptx
Module 08 Access & Use Database Application.pptxModule 08 Access & Use Database Application.pptx
Module 08 Access & Use Database Application.pptx
 
Master database management for cxc
Master database management for cxcMaster database management for cxc
Master database management for cxc
 
Operate Spreadsheet applications ppt.pptx
Operate Spreadsheet applications ppt.pptxOperate Spreadsheet applications ppt.pptx
Operate Spreadsheet applications ppt.pptx
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
 
1. access
1. access1. access
1. access
 
Dbms question
Dbms questionDbms question
Dbms question
 
Access2003
Access2003Access2003
Access2003
 
Access2003
Access2003Access2003
Access2003
 
10359485
1035948510359485
10359485
 
Intro To TSQL - Unit 1
Intro To TSQL - Unit 1Intro To TSQL - Unit 1
Intro To TSQL - Unit 1
 
Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6Object Oriented Programming with Laravel - Session 6
Object Oriented Programming with Laravel - Session 6
 
Sorting, Filtering, and Creating Relationships.pptx
Sorting, Filtering, and Creating Relationships.pptxSorting, Filtering, and Creating Relationships.pptx
Sorting, Filtering, and Creating Relationships.pptx
 

Recently uploaded

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 

Recently uploaded (20)

Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 

Lession 4 the tables of a database

  • 1. Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn 78 Lession 4: The Tables of a Database Tables Fundamentals Introduction A table is primarily a list of items or a group of lists. To manage such a list, it should be meticulously organized. To organize this information, it is divided in sections. Here is an example: Name Age Gender Relationship Judie 18 Female Sister Ernest 24 Male Cousin Bill 52 Unknown Uncle David 36 Male Brother Hermine 12 Unknown Niece Based on this, a list is simply an arrangement of information and this information, also called data, is stored in tables. Visual Creation of a Table The information of a table is organized in categories called columns and horizontal arrangements called records or rows. A column holds a category of data that is common to all records. A table must have at least one column. This means that you cannot create a table without defining at least one column. Tables Names To complete the creation of a table, you must save it. If you are freshly creating a table and decide to save it, you would be prompted to name it. The name of a table: Can be made of digits only. For example you can have a table called 148 Can start with a digit, a letter, or an underscore Can be made of letters, digits, and spaces Besides these rules, you can make up yours. To avoid confusion, here are the rules we will use to name our tables: A name will start with a letter. Examples are 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 Staff Members or Video Titles Creating a Table With SQL Introduction
  • 2. Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn 79 To assist you with creating a table, you use a Data Definition Language (DDL) command that is CREATE TABLE, followed by a name. Therefore, to create a table, you start with the following statement: CREATE TABLE TableName; The CREATE TABLE expression is required. The TableName factor specifies the name of the new table. The TableName can use the rules and suggestions we reviewed for the tables. After specifying the name of the table, you must create at least one category, called a column of data. Temporary Tables After creating a table, it becomes part of its database and you can use that table over and over again. In some cases, you may want to create a table to test something and you would not need to use that table the next time you connect to the server. Such a table is referred to as a temporary table. To create a temporary table, start its name with #, followed by the desired name. Once the table has been created, it would be available as long as you are using the same connection to the server. If you close Microsoft SQL Server, the table would be automatically deleted. Using Sample Code To assist you with creating a table, Microsoft SQL Server can generate sample code for you. You can then simply modify or customize it. First display or open an empty query window. To display the Templates Explorer, on the main menu, you can click View -> Templates Explorer. In the Templates Explorer, expand the Table node. Under table, drag Create Table and drop it in the query window. Sample code would be generated for you. Tables Maintenance Introduction Table maintenance consists of reviewing or changing its aspects. This includes reviewing the list of tables of a database, renaming a table, or deleting it. Viewing the Properties of a Table Like every other object of a database or of the computer, a table possesses some characteristics that are proper to it. To view these characteristics, in the Object Explorer, right-click the table and click Properties. Opening a Table Most operations require that you open a table before using it. There are various ways a table displays, depending on how you want to examine it: To view the structure of a table, perhaps to change its columns, in the Object Explorer, expand your database and its Tables node. Right-click the table and click Modify. The table would open in design view, the same view you use to visually create a table.
  • 3. Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn 80 If you want to view the SQL code of a table, in the Object Explorer, right-click the table, position the mouse on Script Table AS, CREATE To, and click New Query Editor Window To open a table to view its data, perhaps to perform data entry, in the Object Explorer, right-click the table and click Open Table Tables Review To see the list of tables of a database in the Object Explorer, you can click the Tables node: To see the list of tables of a database using SQL, in a Query window, specify the database (using a USEstatement), and execute sp_help (it is a stored procedure). Here is an example:
  • 4. Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn 81 Renaming a Table If you find out that the name of a table is not appropriate, you can change it. To change the name of a table in the SQL Server Management Studio, in the Object Explorer, right- click the table and click Rename. Type the desired name and press Enter. To change the name of a table with code, execute sp_rename, followed by the current name of the table, a comma, and the new desired name of the table. The formula to use is: sp_rename ExistingTableName, TableNewName; The names of tables should be included in single-quotes. Here is an example: sp_rename N'StaffMembers', N'Employees'; GO In this case, the interpreter would look for a table named StaffMembers in the current or selected database. If it finds it, it would rename it Employees. If the table doesn't exist, you would receive an error. Deleting a Table If you have an undesired table in a database, you can remove it. To delete a table in the SQL Server Management Studio, in the Object Explorer, right-click the table under its database node and click Delete. You will receive a warning giving you a chance to confirm your intentions. If you still want to remove the table, click OK. To delete a table using SQL, use the following formula: DROP TABLE TableName The DROP TABLE expression is required and it is followed by the name of the undesired table. When you execute the statement, you will not receive a warning before the table is deleted.
  • 5. Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn 82 You can also use sample code that Microsoft SQL Server can generate for you. First display an empty query window. Also display the Templates Explorer and expand the Table node. Under Table, drag Drop Table and drop it in the empty query window. Sample code would be generated for you. You can then simply modify it and execute the statement. Referring to a Table In future lessons, we will write various expressions that involve the names of tables. In those expressions, you will need to specify a particular table you want to use. There are three main ways you can do this. To refer to, or to indicate, a table: You can simply type its name. An example would be Students You can type dbo, followed by the period operator, followed by the name of the table. An example would be dbo.Students You can type the name of the database to which the table belongs, followed by the period operator, followed by dbo, followed by the period operator, and followed by the name of the table. An example would be RedOakHighSchool.dbo.Students Tables and Permissions The table as an object doesn't have many own rights. Its permissions are controlled partly by its database owner and by its contents. The primary right to exercise on a database is the ability to create a table. To visually allow or deny this, access the Database Properties of the database that owns the table. In the Select a Page list, click Permissions. In the Users or Roles list, select the user. In the Permissions list, locater the Create Table row: After granting or denying access, click OK. To programmatically allow a user to create tables on a database, type GRANT CREATE TABLE TO followed by the name of the user. Here is an example: USE Exercise1; GO GRANT CREATE TABLE TO [Raymond Kouma];
  • 6. Lecturer: Tran Dinh Vuong Home page: www.fit.vimaru.edu.vn/~vuongtd Phone : 0982.113.274 Email : vuongtd@vimaru.edu.vn 83 GO