Escolar Documentos
Profissional Documentos
Cultura Documentos
Relational databases apply mathematical theories to efficiently organize and retrieve data
within a database. Database information is stored in tables, which are made up of rows
and columns. The following graphic shows several components of a database.
Table
Primary
Key
Values for each row and column identify the exact characteristics of
each object instance. For example, the LastName of the second
employee in the table is King.
A primary key is a set of columns guaranteed to have unique values for each
row in a table. For example, in the table above, the EmployeeID column is
the primary key. Each column in any individual row identified by that
primary key will contain a unique ID number for each employee.
Queries
Description
To view or modify data, submit a query to the DBMS.
Queries are written in a structured language that is understood by
the DBMS. For example, SQL server uses Transact-SQL as the
query language.
Client applications submit queries to the DBMS. For example,
database management tools are client applications that connect to
and submit queries to the DBMS.
The DBMS executes the query and returns the result to the client.
Locking
Transactions
After the changes are made, the lock is released, at which time
other clients can lock the data for modification.
transaction.
The application signals the end of the transaction. If the end of the
transaction has been reached without error, the transaction is
committed and the changes become permanent.
If there is an error during the transaction, the DBMS rolls back the
changes, putting the database in its original (unchanged) state.
Description
Enterprise Manager runs as a snap-in for the MMC (Microsoft
Management Console). Through Enterprise Manager you can:
SQL Server
Enterprise
Manager
SQL Query
Analyzer
You can access Query Analyzer from the Start menu, from Enterprise
SQL Profiler
Server Network
Utility
Use the Client Network Utility to set the client Net-Libraries and to
define server aliases.
Use the Server Network Utility to set the server Net-Libraries.
Additionally, the Server Network Utility allows you to specify the
following parameters:
The network protocol stacks where SQL Server 2000 listens for
client requests
The order in which protocols are used for establishing
connections
Osql
BCP
BCP is a command line utility that you can use to copy data from SQL
Server 2000 to a user-defined data file.
What is a trigger?
What does the data type identify?
How is the Money class represented?
How can dates be represented?
System databases are used to store information about SQL Server 2000 and to
operate and manage the system. System databases should not be modified by
users or administrators.
User databases are the databases created by users for storing their unique data.
The following system databases are created by default when SQL Server 2000 is
installed.
Database
Database
Type
master
model
msdb
tempdb
distribution
databases
System
User
Description
Sample
Databases
Description
Tables
Database tables typically consist of columns and rows of data. The rows
represent unique records in the database, while the columns represent fields
within the record.
Views
Views identify the specific data that is displayed at any given time. Views
can specify that only certain rows or columns are visible, can aggregate
(summarize) data, or can collect data from more than one table and present
it as though it were from a single table.
Indexes
A database index is a structured list of the values in the table or view, and
the location of the rows containing that value. Indexes can be clustered,
where the data is sorted and stored based on the index key, or nonclustered,
where the structure of the index is separate from the data rows, and row
locators in the index point to the location of the data in either a clustered
index key or in a heap. (A table that is created with no index is called a
heap, and the data rows are stored in no particular order.)
Keys
Stored
procedures
Constraints
Constraints allow you to define the rules for the values allowed in columns.
While there are other methods of enforcing data integrity (i.e., triggers,
rules, and defaults), using constraints is the standard method for enforcing
data integrity.
Defaults
Triggers
User-defined User-defined data types are based on pre-defined SQL Server 2000 data
data types
types. User-defined data types are typically used when columns holding
similar classes of data must have the same base data type, length, and
nullability. User-defined data types are not supported in table variables.
User-defined functions are uniquely-named subroutines made up of one or
User-defined
more Transact-SQL statements customized by the user for a specific
functions
purpose.
Datatype Facts
Each column, variable, expression, and parameter in SQL Server 2000 has a related data
type. The data type identifies:
The type of data the object can contain (such as text or numeric data)
Any constraints on the maximum size of the data
For numeric data, the number of digits the number can contain (precision
attribute)
For numeric data, and the number of digits that can be stored to the right of the
decimal point (scale attribute)
As you define tables and other database objects and as you construct TSQL statements,
the data type is identified by using a keyword. The following table lists many common
datatype keywords. Note: This list is not comprehensive.
Class
Integer
Bit, Decimal,
Numeric, and
Approximate
Numerics
Money
Keyword
Description
bigint
int
Integer (whole number) data from -231 (2,147,483,648) through 231-1 (2,147,483,647).
smallint
tinyint
bit
decimal
numeric
float
real
money
datetime
smalldatetime
char
varchar
text
Date/Time
Binary Strings
nvarchar
ntext
binary
varbinary
image
A reference to a cursor.
sql_variant
A data type that stores values of various SQL Serversupported data types, except text, ntext, timestamp,
and sql_variant.
table
timestamp
Note: The example shown above is a single query statement. Statements can be written
all on one line or broken into several lines as shown above. When SQL server parses the
query, it identifies all elements that are part of the statement and executes one statement
at a time.
Query statements can contain the following elements:
Component Description
Commands perform functions on the server or the database. Each statement
begins with a command. Four common commands are:
SELECT retrieves rows from a table
UPDATE changes data in a table
Commands
INSERT adds a row to a table or a view
Keywords
Keywords are words that SQL uses for its own functionality. Keywords
include commands as well as command parameters. In the example shown
above, the FROM and WHERE are keywords.
Note: Within documentation, keywords are written in all capital letters.
When you write Transact-SQL statements, case does not matter.
Identifiers
Functions
Operators perform actions on data. For example, you can use arithmetic
operators to perform mathematical operations on the data.
Data types define the format of the data used by table columns or variables.
Each data type is identified by a keyword. When you are constructing
Data Types
statements, you might need to identify the data type of any variables used
within the statement.
Comments are nonexecuting remarks in a statement. Comments are indicated
in one of two ways:
Double hyphens ( -- ). Any text on a line following the double
hyphen will not be included as part of the statement. Text on a new
line that is not preceded by the double hyphens is not commented.
Forward slash-asterisk pairs ( /* ... */ ). Any text inside the
character pair will not be executed, even if it spans multiple lines.
Comments
When you look up commands in the SQL documentations, you will see something like
the following:
SELECT select_list
[INTO new_table_name]
FROM table_list
[WHERE search_conditions]
[GROUP BY group_by_list]
[HAVING search_conditions]
[ORDER BY order_list [ASC | DESC] ]