0% found this document useful (0 votes)
49 views

SQL Server Data Types

This document summarizes different SQL data types and user-defined data types. It also discusses how table variables can be used in stored procedures. Specifically: 1) It describes common SQL data types like char, varchar, bit, int, bigint, smallint, and tinyint. 2) It explains that user-defined data types allow custom names and formats to be given to common data types for consistency. 3) When used in stored procedures, table variables behave like local variables and provide benefits over temporary tables like fewer recompilations and less locking/logging resources due to their more limited scope.

Uploaded by

asasidhar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

SQL Server Data Types

This document summarizes different SQL data types and user-defined data types. It also discusses how table variables can be used in stored procedures. Specifically: 1) It describes common SQL data types like char, varchar, bit, int, bigint, smallint, and tinyint. 2) It explains that user-defined data types allow custom names and formats to be given to common data types for consistency. 3) When used in stored procedures, table variables behave like local variables and provide benefits over temporary tables like fewer recompilations and less locking/logging resources due to their more limited scope.

Uploaded by

asasidhar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Complied by John .

K & Bharat
DATA TYPES

Char – Fixed data type. So it takes up whatever size is assigned, even if not used.

Varchar – Variable data type. Takes up space of the #character entered and not
the size assigned.

Bit type – datatype which express Boolean value. Used to store Boolean
information. Before 7.0 it stores only two states (0 and 1) from 7.0 on it has 3 states
(0, 1 , NULL)

Int – (4), BigInt – (8) From SQL2000 only, Small Int – (2), TinyInt – (1)

User defined data-types

Lets you extend the base SQL server data types by providing a descriptive name
and format to the database. Eg. Flight_# appears in many tables and all these
tables have varchar(8) Create a user defined data-type.

1. If a stored procedure is taking a table data type, how it looks?


• A table variable behaves like a local variable. It has a well-defined scope, which is the
function, stored procedure, or batch in which it is declared.
Within its scope, a table variable may be used like a regular table. It may be applied
anywhere a table or table expression is used in SELECT, INSERT, UPDATE, and
DELETE statements. However, table may not be used in the following statements:

INSERT INTO table_variable EXEC stored_procedure


SELECT select_list INTO table_variable statements.

table variables are cleaned up automatically at the end of the function, stored procedure,
or batch in which they are defined.
• table variables used in stored procedures result in fewer recompilations of the stored
procedures than when temporary tables are used.
• Transactions involving table variables last only for the duration of an update on the table
variable. Thus, table variables require less locking and logging resources.

Jan 2007

You might also like