IT Community - Software Programming, Web Development and Technical Support

Difference of the data types.

This is a discussion on Difference of the data types. within the Database Support forums, part of the Web Development category; Hi all... Can we discuss briefly about the difference of data types. What is the difference between the char and ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-07-2008, 04:39 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Difference of the data types.

Hi all...


Can we discuss briefly about the difference of data types.

What is the difference between the char and varchar?

Thanks in advance...

Last edited by itbarota : 04-07-2008 at 04:46 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-07-2008, 04:44 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: Difference between the char and varchar

Hi all...


CHAR and VARCHAR data types are both non-Unicode character data types with a maximum length of 8,000 characters. The main difference between these 2 data types is that a CHAR data type is fixed-length while a VARCHAR is variable-length. If the number of characters entered in a CHAR data type column is less than the declared column length, spaces are appended to it to fill up the whole length.

Another difference is in the storage size wherein the storage size for CHAR is n bytes while for VARCHAR is the actual length in bytes of the data entered (and not n bytes).


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-07-2008, 04:49 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...



Can anyone tell me the difference of nchar and nvarchar.



Thanks in advance....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-07-2008, 05:21 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: Difference of the data types.

Both nchar and nvarchar are Unicode datatypes and use the UNICODE UCS-2 character set.

nchar:
  • Character data types that are with fixed-length.
  • The value of nchar are from 1 through 4,000.
  • The storage size is two times n bytes.
  • The SQL-2003 synonyms for nchar are national char and national character.

nvarchar:
  • Character data types that are with variable-length.
  • The maximum storage size is 2^31-1 bytes.
  • The storage size, in bytes, is two times the number of characters entered + 2 bytes.
  • The data entered can be 0 characters in length.
  • The SQL-2003 synonyms for nvarchar are national char varying and national character varying.

Note:

When n is not specified in a data definition or variable declaration statement, the default length is 1.
When n is not specified with the CAST function, the default length is 30.

When to Use nchar and nvarchar datatypes:

  • Use nchar when the sizes of the column data entries are probably going to be similar.
  • Use nvarchar when the sizes of the column data entries are probably going to vary considerably.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 07:53 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...


Can anyone tell me the difference of char and nchar.


Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 07:56 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: Difference of the char and nchar.

Hi all...


CHAR and NCHAR data types are both character data types that are fixed-length. Below is the summary of the differences between these 2 data types:

char:
Char is non-unicode data.
char maximum length is 8,000
Character size is 1 byte
storage size is n bytes

nchar:
nchar is unicode data
ncar maximum length is 4,000
character size is 2 bytes
storage size is 2 time n bytes

When do i use them.
You would use NCHAR data type for columns that store characters from more than one character set or when you will be using characters that require 2-byte characters, which are basically the Unicode characters such as the Japanese Kanji or Korean Hangul characters.


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-10-2008, 08:02 PM
KiruthikaSambandam KiruthikaSambandam is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 332
KiruthikaSambandam is on a distinguished road
Default Re: Difference of the data types.

Hi,

Char[(n)]
- datatype can store up to 8000 bytes of fixed-length character data. You can specify the maximum byte length with n.

nchar[(n)] - datatype can store up to 4000 bytes of fixed-length unicode character data. You can specify the maximum byte length with n.

Thanks
Kiruthika
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 04-10-2008, 08:20 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...


Difference of varchar and nvarchar.


Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 04-10-2008, 08:23 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Difference of varchar and nvarchar.

Hi all...


VARCHAR and NVARCHAR data types are both character data types that are variable-length. Below is the summary of the differences between these 2 data types:

varchar[n]:
varchar is non-unicode data
varchar maximum length is 8,000
character size is 1 byte
storage size is actual length (in bytes)

nvarchar[n]:
nvarchar is unicode data
nvarchar maximum length is 4,000
character size is 2 bytes
storage size is 2 times actual length (in bytes)

when do used them:
You would use NVARCHAR data type for columns that store characters from more than one character set or when you will be using characters that require 2-byte characters, which are basically the Unicode characters such as the Japanese Kanji or Korean Hangul characters.

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 04-11-2008, 08:18 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...



Can anyone tell me the difference of tinyint,smallint,int and bigint.


Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 04-11-2008, 08:22 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: Difference of the data types.

Hi all...



TINYINT, SMALLINT, INT and BIGINT are all the same in the sense that they are all exact number data types that use integer data. The difference between these data types are in the minimum and maximum values that each can contain as well as the storage size required by each data type, as shown in the following table:

tinyint:
Minimum value is 0 and Maximum value is 255
Storage size is 1 byte

smallint:
Minimum value is -2^15(-32768) and maximum value is 2^15-1(32,767)
Storage size is 2 bytes

int:
Minimum value is -2^31(-2,147,483,648) and maximum value is
2^31-1(2,147,483,647)
Storage size is 4 bytes

bigint:
Minimum value is 2^63 (-9,223,372,036,854,775,808) and maximum
value is 2^63 - 1 (9,223,372,036,854,775,807)

When do i used them?
Choosing which of these data types to use depends on the value you want to store for the column or variable. The rule of thumb is to always use the data type that will require the least storage size. Don't always use INT as your data type for whole numbers if you don't need to. If you simply need to store a value between 0 and 255 then you should define your column as TINYINT.


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 04-14-2008, 08:02 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...


Can anyone tell me the difference of numeric and decimal.


Thanks in advance
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 04-14-2008, 08:05 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Difference of numeric and decimal.

Hi all...


There is no difference between NUMERIC and DECIMAL data types. They are synonymous to each other and either one can be used. DECIMAL/NUMERIC data types are numeric data types with fixed precision and scale.

DECIMAL (p [, s ])
NUMERIC (p [, s ])

In declaring a DECIMAL or NUMERIC data type, p, which is the precision, specifies the maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The s is the scale and it specifies the maximum number of decimal digits that can be stored to the right of the decimal point. Scale, which defaults to 0 if not specified, must be a value from 0 to the precision value.

The following table specifies the storage size required based on the precision specified for the NUMERIC or DECIMAL data type:

precision storage size
1 - 9 5 bytes
10-9 9 bytes
20-28 13 bytes
29-38 17 bytes

Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 04-14-2008, 08:06 PM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Re: Difference of the data types.

Hi all...


Can anyone tell me the difference of float and real.



Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 04-14-2008, 08:21 PM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Difference of float and real.

Hi all...


FLOAT and REAL data types are both approximate number data types for use with floating point numeric data. Floating point data is approximate; not all values in the data type range can be precisely represented. The differences between these 2 data types are in the minimum and maximum values each can hold as well as the storage size required, as specified in the following table:

Data Type n Minimum value Maximum value Precision Storage
Size
Float[(n)] 1-24 -1.79E+308 1.79E+308 7digits 4bytes
25-53 -1.79E+308 1.79E+308 15digits 8bytes
Real -3.40E+38 3.40E+38 7digits 4bytes

For FLOAT data type, the n is the number of bits used to store the mantissa in scientific notation and thus dictates the precision and storage size and it must be a value from 1 through 53. If not specified, this defaults to 53. In SQL Server, the synonym for REAL data type is FLOAT(24). If your data requires only a maximum of 7 digits precision, you can either use the REAL data type or FLOAT data type with 24 as the parameter (FLOAT(24)).


Thanks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 04-16-2008, 04:10 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...


Can anyone tell me the difference of smalldatetime and datetime.



Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 04-16-2008, 04:20 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Difference of smalldatetime and datetime.

Hi all...


A datetime data type is date and time data from January 1, 1753 through December 31, 9999, to an accuracy of one three-hundredth of a second (equivalent to 3.33 milliseconds or 0.00333 seconds). Values are rounded to increments of .000, .003, or .007 seconds.

On the other hand, a smalldatetime data type is a date and time data from January 1, 1900, through June 6, 2079, with accuracy to the minute. smalldatetime values with 29.998 seconds or lower are rounded down to the nearest minute; values with 29.999 seconds or higher are rounded up to the nearest minute.

Values with the datetime data type are stored internally by Microsoft SQL Server as two 4-byte integers. The first 4 bytes store the number of days before or after the base date, January 1, 1900. The base date is the system reference date. Values for datetime earlier than January 1, 1753, are not permitted. The other 4 bytes store the time of day represented as the number of milliseconds after midnight.

The smalldatetime data type stores dates and times of day with less precision than datetime. SQL Server stores smalldatetime values as two 2-byte integers. The first 2 bytes store the number of days after January 1, 1900. The other 2 bytes store the number of minutes since midnight. Dates range from January 1, 1900, through June 6, 2079, with accuracy to the minute.

Smalldatetime:

Minimum value of smalldatetime is january 1, 1990 and the maximum
value is june 6, 2079.

Time accuracy is up to a minute.

Storage size is 4 bytes.

Datetime:

Minimum value of datetime is jan 1, 1753 and the maximum value is
december 31, 9999.

Time accuracy is one three-hundredth of a second.

Storage size is 8 bytes

smalldatetime is usually used when you don't need to store the time of the day such as in cases of effectivity dates and expiration dates. datetime is used if the time of the day is needed and up to the second accuracy is required.


Thanks...

Last edited by Pvinothkumar : 04-16-2008 at 04:25 AM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 04-16-2008, 04:27 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 547
itbarota is on a distinguished road
Default Re: Difference of the data types.

Hi all...


Can anyone explain me the difference of smallmoney and money.


Thanks in advance
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 04-16-2008, 04:35 AM
Pvinothkumar Pvinothkumar is offline
D-Web Analyst
 
Join Date: Sep 2007
Posts: 237
Pvinothkumar is on a distinguished road
Default Difference of smallmoney and money.

Hi all...


MONEY and SMALLMONEY are both monetary data types for representing monetary or currency values. The differences between these 2 data types are in the minimum and maximum values each can hold as well as in the storage size required by each data type, as shown in the following table:

Smallmoney:

Minimum value is -247,748.3648 and the maximum value is 214,748.3647.

Storage size is 4 bytes.

Money:

Minimum value is -2^63(-922,337,203,685,477,5808) and the maximum
value is 2^63 - 1 (+922,337,203,685,477.5807).

Storage size is 8 bytes.

Both SMALLMONEY and MONEY data types has an accuracy to a ten-thousandths of a monetary unit. The rule of thumb is to always use the data type that will require the least storage size. If the monetary value that you will store is less than 214,748.3647 then you should use SMALLMONEY; otherwise use the MONEY data type.


Thanks in advance...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server Data Types and Ranges. Sundaram Database Support 6 02-22-2008 02:11 AM
What is the difference between CHAR and VARCHAR data types? sundarraja Database Support 1 02-01-2008 09:36 PM
What is the difference between global and action sheets within the data table in QTP? sundarraja Testing Tools 1 08-13-2007 10:50 PM
How can I implement opaque (abstract) data types in C? prasath C and C++ Programming 1 07-30-2007 03:24 AM
Java:Tutorial - Data Types pranky Java Programming 0 02-23-2007 11:47 PM


All times are GMT -7. The time now is 12:31 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0