SQL Server Question | Can we declare a variable/ define a column as INTEGER or DEC?
Well yes we can. We can declare a variable as INTEGER. INTEGER is a synonym for INT and DEC is a synonym for DECIMAL. They are called as data type synonyms.
This was asked to me by a client developer. The actual question was – If you define a column as INTERGER and then you see the table properties, What will you see in the properties – INT or INTEGER.?
Be honest – Have you heard of data type synonyms? 🙂
Data type synonyms are included in SQL Server for ISO compatibility. The following table lists the synonyms and the SQL Server system data types that they map to.
Well the Data type synonyms can be used instead of the corresponding base data type name in the following places-
1. Data definition language (DDL) statements, such as CREATE TABLE, CREATE PROCEDURE
2. DECLARE @variable.
Below if the complete table of data type synonyms-
|Synonym||SQL Server system data type|
|character( n )||char(n)|
|character varying( n )||varchar(n)|
|float[(n)] for n = 1-7||real|
|float[(n)] for n = 8-15||float|
|national character( n )||nchar(n)|
|national char( n )||nchar(n)|
|national character varying( n )||nvarchar(n)|
|national char varying( n )||nvarchar(n)|
Note once the the object is created, the synonyms have no visibility. For example if you define a column with INTEGER, once the table is created you will see Int when you check the table properties. When the object is created, the object is assigned the base data type that is associated with the synonym. There is no record that the synonym was specified in the statement that created the object.
-- CREATE TABLE TestDataSyn ( Id INTEGER ) GO --
Screen shot showing that there is no record that the synonym was specified in the statement that created the object
You can read more from below.
Please add comment(s) if you have one or multiple solutions in mind. Thank You.
Pawan is a SQL Server Developer. If you need any help in writing code/puzzle or training please email at – pawankkmr”AT”gmail.com. Meanwhile please go throgh the top pages from his blog.
|☛ SQL Advance Puzzles||https://msbiskills.com/tsql-puzzles-asked-in-interview-over-the-years/|
|☛ SQL Tricky Queries||https://msbiskills.com/sql-puzzles-finding-outputs/|
|☛ SQL Server Performance tuning Articles||https://msbiskills.com/sql-performance-tuning/|
|☛ SQL Server Articles||https://msbiskills.com/t-sql/|
|☛ SQL Interview Questions & Answers||https://msbiskills.com/sql-server-interview-questions/|
My SQL Groups on Facebook:
1. If you like this post, you may want to join my SQL SERVER Interview Puzzles/Interview Questions on Facebook: https://www.facebook.com/groups/1430882120556342/
2. If you like this post, you may want to join my SQL Server Puzzles on Facebook:
My SQL Page on Facebook:
2. For all the updates you may follow my page -> https://www.facebook.com/MSBISkillscom-1602779883299222/
Enjoy !!! Keep Learning
You must be logged in to post a comment.