Tải bản đầy đủ (.pdf) (18 trang)

Instructor InputsSession 2..Session OverviewThis session includes the following topics: pptx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.02 MB, 18 trang )

Instructor Inputs
Session 2

¤NIIT Instructor Inputs 2.3
This session includes the following topics:
 Functions to customize the result set in SQL Server 2005
 Best practices
 Tips and Tricks
 FAQs
Slide 1
Installing Windows XP Professional Using Attended Installation
Slide 1 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Objectives
In this session, you will learn about:
Functions to customize the result set in SQL Server 2005
Best Practices while using procedures and functions in SQL
Server 2005
Tips and Tricks that will help you use functions in SQL Server
2005
FAQs related to general data types and functions in SQL
Server 2005
Session Overview
2.4 Instructor Inputs ¤NIIT
Slide 2
Installing Windows XP Professional Using Attended Installation
Slide 2 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005


Collaborate Session 2
Knowledge Byte
SQL Server 2005 provides many in-built functions to
Customize the Result Set:
String functions:
Are used to manipulate the string values in the result set.
Date Functions:
Are used to manipulate datetime values.
Are used either to perform arithmetic operations on date values
or parse the date values.
Ranking Functions:
Are used to generate sequential numbers for each row or to give
a rank based on specific criteria.
Slide 3
Installing Windows XP Professional Using Attended Installation
Slide 3 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Knowledge Byte (Contd.)
System Functions:
Are used to query the system tables. System tables are a set of
tables that are used by the SQL Server to store information
about users, databases, tables, and security.
Are used to access the SQL Server databases or us er-related
information.
¤NIIT Instructor Inputs 2.5
Slide 4
Installing Windows XP Professional Using Attended Installation
Slide 4 of 21

Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Best Practices
Never start the name of any stored procedure you create,
with the SP prefix. This is because all system stored
procedures start with the SP prefix.
Avoid using the INSERT statement when performing bulk
inserts into your database.
To reference a table from another database in the same
server, prefix the table with the database name. Use the
following syntax to refer a table from another database in
the same server:
SELECT * from [<database name>].[dbo].[< table
name>]
Slide 5
Installing Windows XP Professional Using Attended Installation
Slide 5 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Tips and Tricks
Use SPACE() function for concatenating values in a query.
Use VARCHAR(max) data type with LEFT(), RIGHT(),
SUBSTRING() functions because these functions do not
support ntext and text data types.
Analyze all your query plans by using the SQL Query
Analyzer to ensure that they are performing at optimum
speed.
2.6 Instructor Inputs ¤NIIT

Slide 6
Installing Windows XP Professional Using Attended Installation
Slide 6 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Tips and Tricks (Contd.)
Avoid the use of nullable columns:
The use of the nullable column consumes an extra byte on
each column used and while querying data, there is much
more overhead with nullable columns.
Slide 7
Installing Windows XP Professional Using Attended Installation
Slide 7 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
What is the difference between the DELETE and
TRUNCATE commands?
The DELETE command removes the rows from a table based
on the condition provided with the WHERE clause. The
TRUNCATE command removes all the rows from a table and
does not give an option to selectively delete records.
FAQs
¤NIIT Instructor Inputs 2.7
Slide 8
Installing Windows XP Professional Using Attended Installation
Slide 8 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005

Collaborate Session 2
How can you figure out if a string is completely in
uppercase?
You can find if a string is completely in uppercase by using the
ASCII string function.
FAQs (Contd.)
Slide 9
Installing Windows XP Professional Using Attended Installation
Slide 9 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Can you define any length for a VARCHAR data type, such
as VARCHAR(10000)?
When the length is specified in declaring a VARCHAR variable
or column, the maximum length allowed is 8000 characters. If
the length is greater than 8000 characters, you have to use
the MAX specifier as the length.
FAQs (Contd.)
2.8 Instructor Inputs ¤NIIT
Slide 10
Installing Windows XP Professional Using Attended Installation
Slide 10 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
If there are VARCHAR(MAX), NVARCHAR(MAX) and
VARBINARY(MAX) data types, are there CHAR(MAX),
NCHAR(MAX) and BINARY(MAX) data types also?
No, there is no CHAR(MAX), NCHAR(MAX), or BINARY(MAX)

data types. The main reason why the MAX specifier is not
included for these data types is because these data types are
fixed-length data types. If the MAX specifier is included for
these data types, it will be a big waste of disk space as each
column will consume 2 GB of memory even if only a short
string value is assigned to the column.
FAQs (Contd.)
Slide 11
Installing Windows XP Professional Using Attended Installation
Slide 11 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
How can you turn on IDENTITY on an existing column?
To change an existing column as an IDENTITY column,
perform the following steps:
Modify table in object browser.
Change column property to IDENTITY “yes”.
Save the change.
FAQs (Contd.)
¤NIIT Instructor Inputs 2.9
Slide 12
Installing Windows XP Professional Using Attended Installation
Slide 12 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge
Identify the output of the following command:
Select left(‘SQL Server’,3)

Ser
SQL
ver
QL S
Answer:
SQL
Slide 13
Installing Windows XP Professional Using Attended Installation
Slide 13 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Which function is used to return the length of a string?
length
lenString
StrLen
len
Answer:
len
2.10 Instructor Inputs ¤NIIT
Slide 14
Installing Windows XP Professional Using Attended Installation
Slide 14 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Which string is used to replace a character with another
character?

charindex
Space
stuff
patindex
Answer:
stuff
Slide 15
Installing Windows XP Professional Using Attended Installation
Slide 15 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Which method returns the current date and time?
getdate
date
gettime
time
Answer:
getdate
¤NIIT Instructor Inputs 2.11
Slide 16
Installing Windows XP Professional Using Attended Installation
Slide 16 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
What is the return type of rand function?
numeric

int
float
smallint
Answer:
float
Slide 17
Installing Windows XP Professional Using Attended Installation
Slide 17 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Which join returns the Cartesian Product of the rows of two
tables?
EQUI JOIN
INNER JOIN
CROSS JOIN
OUTER JOIN
Answer:
CROSS JOIN
2.12 Instructor Inputs ¤NIIT
Slide 18
Installing Windows XP Professional Using Attended Installation
Slide 18 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
What does >ALL mean in a SELECT statement that is using
a subquery?

It means greater than the maximum value in the list.
It means any of the values in the list.
It means greater than the minimum value in the list.
It means lesser than the minimum value in the list.
Answer:
It means greater than the maximum value in the list.
Slide 19
Installing Windows XP Professional Using Attended Installation
Slide 19 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Which system database contains all system objects?
Resource database
master database
temdb database
model database
Answer:
Resource database
¤NIIT Instructor Inputs 2.13
Slide 20
Installing Windows XP Professional Using Attended Installation
Slide 20 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Introduction to Hacking/Chapter 1
What should be the size of a transaction log file?

25-40 percent of the database size
25-30 percent of the database size
25-35 percent of the database size
22-40 percent of the database size
Answer:
25-40 percent of the database size
Slide 21
Installing Windows XP Professional Using Attended Installation
Slide 21 of 21
Ver. 1.0
Querying, Managing, and Administering Databases Using SQL Server 2005
Collaborate Session 2
Challenge (Contd.)
Which keyword with the CHECK constraint ensures that the
values entered are from a list of constant expressions?
BETWEEN
IN
ALL
LIKE
Answer:
IN
2.14 Instructor Inputs ¤NIIT
1. b. SQL
2. d. len
3. c. stuff
4. a. getdate
5. c. float
Solutions to Challenge
¤NIIT Instructor Inputs 2.15
1. Which join should be used to retrieve records with values satisfying the join

condition in the common column?
a. Outer Join
b. Inner Join
c. Cross Join
d. Equi Join
2. Which database contains critical data that controls SQL Server operations?
a. model
b. msdb
c. tempdb
d. master
3. What should be the size of the transaction log file?
a. 25-35 percent
b. 25-30 percent
c. 25-40 percent
d. 20-40 percent
4. Which key constraint is used to maintain referential integrity?
a. Foreign key constraint
b. Primary key constraint
c. Unique key constraint
d. Check constraint
5. Which stored procedure is used to bind a rule?
a. sp_bind
b. sp_bindrule
c. sp_rulebind
d. sp_unbindrule
Solutions
1. Inner Join
2. master
3. 25-40 percent
4. Foreign key constraint

5. sp_bindrule
Home Assignment
2.16 Instructor Inputs ¤NIIT
The major requirement of any organization or an enterprise is to store complete and
consistent data. Data integrity is the concept of maintaining consistency and completeness
of data. Data integrity is enforced to ensure that the data in a database is accurate,
consistent, and reliable.
Discuss the broadly classified categories of data integrity. In addition, discuss the
different constraints which can be applied to a table to enforce data integrity.
Instructor Inputs
You can conduct the discussion as follows:
 Move the discussion toward different categories of data integrity.
 Continue the discussion by mentioning the different types of constraints.
 Relate each constraint with the data integrity category.
Solution
Data integrity is enforced to ensure that the data in a database is accurate, consistent, and
reliable. It is broadly classified into the following categories:
 Entity integrity: Ensures that each row can be uniquely identified by an attribute
called the primary key.
 Domain integrity: Ensures that only a valid range of values is stored in a column. It
can be enforced by restricting the type of data, the range of values, and the format of
the data.
 Referential integrity: Ensures that the values of the foreign key match the value of
the corresponding primary key.
 User-defined integrity: Refers to a set of rules specified by a user, which do not
belong to the entity, domain, and referential integrity categories.
When creating tables, the SQL Server allows you to maintain integrity by:
 Applying constraints
 Applying rules
 Using user-defined types

Constraints can be divided into the following types:
 Primary key constraint: Ensures the entity integrity.
 Unique constraint: Ensures the entity integrity.
 Foreign key constraint: Ensures the domain and referential integrity.
Collaborative Exercise
¤NIIT Instructor Inputs 2.17

Check constraint: Ensures the domain and referential integrity.
 Default constraint: Ensures the domain integrity.
2.18 Instructor Inputs ¤NIIT

×