|
INTERVIEW QUESTIONS
DATABASE
MS SQL SERVER
DETAILS
Question: How Extra Digits Are Handled with NUMERIC Data Type Literals?
Answer: Exact numeric data types defined with NUMERIC(p,s) has two limits defined by two parameters: p (precision) and s (scale):
* Maximum number of digits of the integer part (digits before the decimal point) is defined as p-s. If this limit is passed, SQL Server will give you an arithmetic overflow error. * Maximum number of digits of the decimal part (digits after the decimal point) is defined as s. If this limit is passed, SQL Server will perform a round operation.
The tutorial exercise below gives an example of arithmetic overflow errors and rounding operations.
-- Exact numeric value DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 1234567.12; SELECT @x; GO 1234567.12
-- Overflow error: p-s limit passed DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 123456789.12; GO Msg 8115, Level 16, State 8, Line 2 Arithmetic overflow error converting numeric to data type numeric.
-- Rounding on extra decimal digits: s limit passed DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 1234567.12345; SELECT @x; GO 1234567.12
|
|
|
Category |
MS SQL Server Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9374 users |
Added on |
9/23/2014 |
Views |
67438 |
Rate it! |
|
|
Question:
How Extra Digits Are Handled with NUMERIC Data Type Literals?
Answer:
Exact numeric data types defined with NUMERIC(p,s) has two limits defined by two parameters: p (precision) and s (scale):
* Maximum number of digits of the integer part (digits before the decimal point) is defined as p-s. If this limit is passed, SQL Server will give you an arithmetic overflow error. * Maximum number of digits of the decimal part (digits after the decimal point) is defined as s. If this limit is passed, SQL Server will perform a round operation.
The tutorial exercise below gives an example of arithmetic overflow errors and rounding operations.
-- Exact numeric value DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 1234567.12; SELECT @x; GO 1234567.12
-- Overflow error: p-s limit passed DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 123456789.12; GO Msg 8115, Level 16, State 8, Line 2 Arithmetic overflow error converting numeric to data type numeric.
-- Rounding on extra decimal digits: s limit passed DECLARE @x NUMERIC(9,2); -- NUMERIC(p,s) SET @x = 1234567.12345; SELECT @x; GO 1234567.12 Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
What Happens If an Integer Is Too Big for INT Date Type?
|
View Answer
|
|
What Are Out-of-Range Errors with Date and Time Literals?
|
View Answer
|
|
What Happens If Time-Only Values Are Provided as Date and Time Literals?
|
View Answer
|
|
What Happens If Date-Only Values Are Provided as Date and Time Literals?
|
View Answer
|
|
Why I Can Not Enter 0.001 Second in Date and Time Literals in MS SQL Server?
|
View Answer
|
|
How To Enter Date and Time Literals in MS SQL Server?
|
View Answer
|
|
How To Enter Binary String Literals in MS SQL Server?
|
View Answer
|
|
How To Enter Unicode Character String Literals in MS SQL Server?
|
View Answer
|
|
How Fixed Length Strings Are Truncated and Padded?
|
View Answer
|
|
How To Find Out What Is the Default Collation in a Database?
|
View Answer
|
|
What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server?
|
View Answer
|
|
How To Specify the Collation for a Character Data Type in MS SQL Server?
|
View Answer
|
|
What Is a Collation in MS SQL Server?
|
View Answer
|
|
How To Write Character String Constants or Literals in MS SQL Server?
|
View Answer
|
|
What Is a Constant or Literal in MS SQL Server?
|
View Answer
|
|
What Are the Differences between DECIMAL and FLOAT in MS SQL Server?
|
View Answer
|
|
What Are the Differences between CHAR and VARCHAR in MS SQL Server?
|
View Answer
|
|
What Are the Differences between CHAR and NCHAR in MS SQL Server?
|
View Answer
|
|
What Are Binary String Data Types in MS SQL Server?
|
View Answer
|
|
What Are Unicode Character String Data Types in MS SQL Server?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All MS SQL Server Interview Questions & Answers - Exam Mode /
Learning Mode
|