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

CollaborateChapter 2..Knowledge ByteIn this section, you will learn about: Functions to pps

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 (228.54 KB, 8 trang )

Collaborate
Chapter 2

Querying, Managing, and Administering Databases Using SQL Server 2005 2.3
¤NIIT
In this section, you will learn about:
 Functions to customize the result set in SQL Server 2005
Read the following section of Chapter 2 of the book Querying and Managing Data Using
SQL Server 2005:
 Using Functions to Customize the Result Set
Knowledge Byte
Using Functions to Customize the Result Set
¤NIIT
2.4 Querying, Managing, and Administering Databases Using SQL Server 2005
This section contains:
 Best practices
 Tips and tricks
 FAQs
The following best practices can be considered while using procedures and functions in
SQL Server 2005:
 Naming stored procedures: 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.
 Using the INSERT statement: Avoid using the INSERT statement when
performing bulk inserts into your database.
 Using a table from another 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>]
The following tips and tricks will help you use functions in SQL Server 2005:
 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. The best things any serious developer can do to
improve performance in an application is to learn to use the SQL Query Analyzer.
Using this tool, you can find where the bottlenecks in your code are and, thereby,
increase performance by altering indexes or even re-writing stored procedures.
 Avoid the use of nullable columns. The use of the nullable column consumes an
extra byte on each column used. While querying data, there is much more overhead
with nullable columns. While designing a database, you should use an alternative
method to allow for a representation of zero data in the column, such as giving “–“ as
the default value for a column of char type.
From the Expert’s Desk
Tips and Tricks
Best Practices
Querying, Managing, and Administering Databases Using SQL Server 2005 2.5
¤NIIT
 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.
 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.
 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.
 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.
 How can you turn on IDENTITY on an existing column?
To change an existing column as an IDENTITY column, perform the following
steps:
a. Modify table in object browser.
b. Change column property to IDENTITY “yes”.
c. Save the change.
FAQs
¤NIIT
2.6 Querying, Managing, and Administering Databases Using SQL Server 2005
1. Identify the output of the following command:
Select left(‘SQL Server’,3)
a. Ser
b. SQL
c. ver
d. QL S
2. Which function is used to return the length of a string?
a. length
b. lenString
c. StrLen
d. len
3. Which string is used to replace a character with another character?
a. charindex
b. space
c. stuff
d. patindex

4. Which method returns the current date and time?
a. getdate
b. date
c. gettime
d. time
5. What is the return type of rand function?
a. numeric
b. int
c. float
d. smallint
Challenge
Querying, Managing, and Administering Databases Using SQL Server 2005 2.7
¤NIIT
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
6. Which join returns the Cartesian Product of the rows of two tables?
a. EQUI JOIN
b. INNER JOIN
c. CROSS JOIN
d. OUTER JOIN
Home Assignment
¤NIIT
2.8 Querying, Managing, and Administering Databases Using SQL Server 2005
7. What does >ALL mean in a SELECT statement that is using a subquery?
a. It means greater than the maximum value in the list.
b. It means any of the values in the list.
c. It means greater than the minimum value in the list.
d. It means lesser than the minimum value in the list.
8. Which system database contains all system objects?
a. Resource database
b. master database
c. temdb database
d. model database
9. What should be the size of a transaction log file?

a. 25-40 percent of the database size
b. 25-30 percent of the database size
c. 25-35 percent of the database size
d. 22-40 percent of the database size
10. Which keyword with the CHECK constraint ensures that the values entered are from
a list of constant expressions?
a. BETWEEN
b. IN
c. ALL
d. LIKE

×