Professional Documents
Culture Documents
TCS Internal 1
Objective
TCS Internal 2
Scope
TCS Internal 3
Transact – SQL Overview
TCS Internal 4
Referring to Objects
[
server_name. [database_name]. [owner_name].
| database_name. [owner_name].
| owner_name.
]
]
object_name
where,
server_name specifies a linked server name or remote
server name.
database_name specifies the name of a Microsoft SQL
Server database when the object resides in a SQL
Server database. It specifies an OLE DB catalog when
the object is in a linked server.
TCS Internal 5
Referring to Objects
TCS Internal 7
Constants or literal values
Examples:
‘sqlserver2005’ – String constant
0x53678CDF – Hexadecimal constant
130 – Numeric constant
TCS Internal 8
Delimiters or Comments
Examples:
/* Employee Table */
-- Inserting the records
TCS Internal 9
Identifiers
The first character can be a letter from the Unicode character set. This includes the
standard US English a-z and A-Z characters as well as foreign letters
Identifiers can be up to 128 characters long, except for the names of local
temporary tables, which can be upto 116 characters long.
Identifiers cannot be a SQL Server reserved word in either upper or lower case.
Identifiers cannot contain embedded spaces or special characters other than those
specified above.
TCS Internal 10
Reserved Keywords
The reserved words are reserved for the use of SQL Server
and should not be used for the names of objects in a
database.
TCS Internal 11
Data Types
Data types define the types of data contained by data objects, such as
columns, variables, and parameters.
The data type is the first characteristic that is defined for the column of a
table.
The data type of a column controls the type of information that can be
stored within the column
TCS Internal 12
Numeric Data Types
TCS Internal 13
String Data Types
There are three types of string data types : character, binary and bit
string.
Character string data types are:
Char [n]
Text [n]
Ntext [n]
Binary [n]
Image [n]
TCS Internal 14
New Data types in SQL 2005
SQL Server 2005 introduces three new data types concerning LOB’s
(Large Objects)
The data types are:
VARCHAR(MAX)
NVARCHAR(MAX)
VARBINARY(MAX)
TCS Internal 15
Date and/or Time data types
SQL Server 2005 supports the following date and time data types.
DATETIME
SMALLDATETIME
TCS Internal 16
Derived data types
SQL Server 2005 supports two data types that can be derived from
simple data types.
The data types are:
TIMESTAMP
SYSNAME
TCS Internal 17
Miscellaneous data types
SQL Server 2005 supports several data types that do not belong to
any of the data type groups described previously.
The are as follows:
CURSOR
UNIQUEIDENTIFIER
SQL_VARIANT
TABLE
XML
TCS Internal 18
User-Defined data types
A user can define his own datatype, which can then be used as a datatype
for a storage structure such as a table column.
TCS Internal 19
Predicates
TCS Internal 20
FUNCTIONS
Functions take zero, one, or more input values and return a scalar
value or a tabular set of values.
Aggregate functions
Scalar functions.
TCS Internal 21
Aggregate Functions
AVG,MAX,MIN,SUM,COUNT,COUNT_BIG
TCS Internal 22
Scalar Functions
Numeric Functions
Date Functions
String Functions
Text/Image functions
System functions
TCS Internal 23
Numeric Functions
TCS Internal 24
Date Functions
GETDATE,DATEPART,DATENAME,DATEDIFF,DATEADD
TCS Internal 25
String Functions
ASCII,CAST,CHAR,CONVERT,CHARINDEX,DIFFERENCE,LOWER,LT
RIM,NEWID,REPLACE,REVERSE,RIGHT,RTRIM,SOUNDEX,SPACE,S
TR,STUFF,SUBSTRING,UPPER
TCS Internal 26
System Functions
COALESCE,COL_LENGTH,Col_NAME,DB_ID,HOST_ID,HOST_NAME
,INDEX_COL,ISNULL,OBJECT_ID,SUSER_SID,SUSER_SNAME,USE
R_NAME,USER,SYSTEM_USER,CURRENT_USER
TCS Internal 27
Text/Image Functions
PATINDEX,TEXTPTR,TEXTVALID
TCS Internal 28
Scalar Operators
TCS Internal 29
Global Variables
@@CONNECTIONS,@@CPU_BUSY,@@IDLE,@@VERSION,@@
PROCID,@@SPID,@@TOTAL_READ
TCS Internal 30