What are the data types in SQL Server?
Every column, variable, parameter and expression in SQL Server has a data type. Microsoft defines it as “an attribute that specifies the type of data that the object can hold”: integer data, character data, monetary data, date and time data, binary strings. The T-SQL data types come in seven categories:
- Exact numerics:
tinyint,smallint,int,bigint,bit,decimalandnumeric(the same type),money,smallmoney. - Approximate numerics:
floatandreal. - Date and time:
date,time,datetime2,datetimeoffset,datetime,smalldatetime. - Character strings:
char,varchar, and the deprecatedtext. - Unicode character strings:
nchar,nvarchar, and the deprecatedntext. - Binary strings:
binary,varbinary, and the deprecatedimage. - Other types, among them
uniqueidentifier,rowversion,xml, the spatial types, andjsonandvector, which need SQL Server 2025 or Azure SQL.
Microsoft’s pages give each one its range, and so do most articles on SQL data types. A list doesn’t tell you which one a column needs, though. That depends on what the column holds, so this post works through a hospital, cut down from the hospital management system template, family by family. Patients, their admissions and their invoices to start:
CREATE TABLE dbo.Patient ( PatientId int IDENTITY(1, 1) NOT NULL CONSTRAINT PK_Patient PRIMARY KEY, MedicalRecordNumber varchar(20) NOT NULL CONSTRAINT AK_Patient_MedicalRecordNumber UNIQUE, FullName nvarchar(200) NOT NULL, BirthDate date NOT NULL, IsOrganDonor bit NULL ); CREATE TABLE dbo.Admission ( AdmissionId int IDENTITY(1, 1) NOT NULL CONSTRAINT PK_Admission PRIMARY KEY, PatientId int NOT NULL, AdmittedAt datetime2(0) NOT NULL, DischargedAt datetime2(0) NULL, CONSTRAINT FK_Admission_Patient_PatientId FOREIGN KEY (PatientId) REFERENCES dbo.Patient (PatientId) ); CREATE TABLE dbo.Invoice ( InvoiceId int IDENTITY(1, 1) NOT NULL CONSTRAINT PK_Invoice PRIMARY KEY, AdmissionId int NOT NULL, Total decimal(12, 2) NOT NULL, InsurerPaid decimal(12, 2) NOT NULL, IssuedOn date NOT NULL, CONSTRAINT FK_Invoice_Admission_AdmissionId FOREIGN KEY (AdmissionId) REFERENCES dbo.Admission (AdmissionId) );

int vs bigint for keys
int takes 4 bytes and holds -2,147,483,648 to 2,147,483,647. bigint takes 8 bytes and goes past nine quintillion. smallint (2 bytes, up to 32,767) and tinyint (1 byte, 0 to 255) fit short lists such as a status code. Microsoft calls int the primary integer type and bigint the one for values that might exceed it.
The limit is real, and an identity column hits it like any other value. Here the admissions identity is moved to just below the top of int:
INSERT INTO dbo.Patient (MedicalRecordNumber, FullName, BirthDate) VALUES ('MRN-10001', N'Ana Souza', '1984-06-02'); DBCC CHECKIDENT ('dbo.Admission', RESEED, 2147483646); INSERT INTO dbo.Admission (PatientId, AdmittedAt) VALUES (1, '2026-03-14 08:30'), (1, '2026-03-20 10:05'); INSERT INTO dbo.Admission (PatientId, AdmittedAt) VALUES (1, '2026-04-02 21:40');
Msg 8115, Level 16, State 1, Line 10
Arithmetic overflow error converting IDENTITY to data type int.
Arithmetic overflow occurred.The first two admissions get 2,147,483,646 and 2,147,483,647. The third has no number left, and the insert fails. No hospital admits two billion patients, so int is right for PatientId and AdmissionId. A lab result table that stores every reading of every test is another matter, and its key gets bigint below.
The choice is cheap to make in CREATE TABLE and expensive to change. Widening dbo.Admission.AdmissionId to bigint later fails with Msg 5074 for PK_Admission, again for Invoice’s foreign key, then Msg 4922. Every table that comes to point at admissions adds one more 5074. The key and each foreign key on it have to go before the columns can change.
decimal vs float for lab values
decimal(p, s) stores exactly p digits, s of them after the point, so decimal(9, 3) holds up to 999,999.999. Precision goes up to 38. As it grows, a decimal takes 5, 9, 13 or 17 bytes. float is a binary floating-point number of 8 bytes, good for about 15 significant digits. real takes 4 bytes and keeps about 7. As Microsoft’s float page says, many values can’t be stored exactly, only an approximation of them.
A ward gives three doses of 0.1 mg and checks the total against 0.3:
DECLARE @DoseF float = 0.1; DECLARE @DoseD decimal(9, 3) = 0.1; SELECT IIF(@DoseF * 3 = 0.3, 'equal', 'not equal') AS FloatTotal, IIF(@DoseD * 3 = 0.3, 'equal', 'not equal') AS DecimalTotal, CONVERT(varchar(30), @DoseF * 3, 3) AS FloatDigits;
The float total isn’t equal to 0.3; the decimal one is. Style 3 of CONVERT prints all 17 digits of the float: 3.0000000000000004e-001. The literal 0.3 becomes a float a little below it, 2.9999999999999999e-001, so the comparison fails. Microsoft’s advice follows from it: no float where exact results, rounding or = comparisons matter, and on a float column use < and > in WHERE, never =.
A lab reports a potassium level as 4.1 mmol/L, to a fixed number of decimals, so its column is decimal. Size it for what the lab reports, because SQL Server rounds what has more decimals and refuses what has more digits:
SELECT CAST(4.25 AS decimal(4, 1)) AS Potassium; SELECT CAST(1234.50 AS decimal(5, 2)) AS Total;
Msg 8115, Level 16, State 8, Line 3
Arithmetic overflow error converting numeric to data type numeric.4.25 is stored as 4.3, silently. 1234.50 doesn’t fit in decimal(5, 2) at all. float is for values that come out of calculations and span many magnitudes, compared by range.
money vs decimal for amounts
money is an 8-byte number with four decimal places; smallmoney takes 4 bytes and stops at 214,748.3647. Both store amounts exactly; the difference shows in arithmetic. The insurer paid 2,469.13 of a 20,000.00 invoice, and the billing code works out the insurer’s share to split that payment across the invoice’s lines:
DECLARE @Total money = 20000.00, @Paid money = 2469.13; DECLARE @TotalD decimal(12, 2) = 20000.00; DECLARE @PaidD decimal(12, 2) = 2469.13; SELECT @Paid / @Total AS MoneyShare, @Paid / @Total * @Total AS MoneyBack, @PaidD / @TotalD AS DecimalShare, @PaidD / @TotalD * @TotalD AS DecimalBack;
money divided by money is money, so the share comes out as 0.1234, the digits past the fourth decimal dropped. Multiplied back, it gives 2,468.00. That is 1.13 short of what the insurer paid. SQL Server sizes a decimal division’s result from its operands (precision, scale, and length), so the decimal share keeps 15 decimal places: 0.123456500000000. Multiplied back, it gives 2,469.13.
Microsoft’s own page for money warns about rounding errors through truncation and says to use decimal, with at least four decimal places, for amounts that go into calculations. That’s why Invoice.Total and InsurerPaid are decimal(12, 2). They hold amounts to the cent, up to 9,999,999,999.99, in 9 bytes.
Text, dates, flags and GUIDs
Text a person writes, such as FullName, goes in nvarchar. Codes the hospital issues in a fixed alphabet, such as MedicalRecordNumber, can be varchar, at one byte a character. Why, and what it costs to mix the two in a comparison, is in nvarchar vs varchar.
BirthDate is a date, 3 bytes with no time of day. AdmittedAt is datetime2(0), whole seconds in 6 bytes. Older schemas use datetime, which rounds to 1/300 of a second and starts in 1753; datetime2 vs datetime shows where that goes wrong.
bit is the flag: 1, 0 or NULL, and up to eight bit columns of a table share one byte (bit). Converting to it is lenient:
SELECT CAST(5 AS bit) AS FromFive, CAST('TRUE' AS bit) AS FromTrue, CAST('false' AS bit) AS FromFalse;
5 becomes 1, any nonzero value does, and the strings 'TRUE' and 'false' become 1 and 0. IsOrganDonor allows NULL on purpose: a patient nobody has asked is neither yes nor no.
A uniqueidentifier is a GUID. It takes 16 bytes, four times as many as an int. It fits an id that another system issues, such as the lab analyzer’s sample id below. As a clustered key, values from NEWID() land in random places in the index. NEWSEQUENTIALID() keeps them in order, but only as a column’s default (NEWSEQUENTIALID). A GUID can’t be an identity, either. A scanned consent form goes in varbinary(max), never in image, which is deprecated along with text and ntext.
A foreign key needs its key’s exact type
Lab results pile up, every test of every admission, so their table gets a bigint key. Whoever writes it types AdmissionId as bigint too, to match:
CREATE TABLE dbo.LabResult ( LabResultId bigint IDENTITY(1, 1) NOT NULL CONSTRAINT PK_LabResult PRIMARY KEY, AdmissionId bigint NOT NULL, SampleId uniqueidentifier NOT NULL, TestCode varchar(10) NOT NULL, Value decimal(9, 3) NOT NULL, Unit varchar(20) NOT NULL, TakenAt datetime2(0) NOT NULL, IsCritical bit NOT NULL, CONSTRAINT FK_LabResult_Admission_AdmissionId FOREIGN KEY (AdmissionId) REFERENCES dbo.Admission (AdmissionId) );

Msg 1778, Level 16, State 1, Line 1
Column 'dbo.Admission.AdmissionId' is not the same data type as referencing column 'LabResult.AdmissionId' in foreign key 'FK_LabResult_Admission_AdmissionId'.
Msg 1750, Level 16, State 1, Line 1
Could not create constraint or index. See previous errors.A foreign key column must have the same type as the key it references. A wider integer is no exception: bigint can hold every int, and SQL Server still refuses it with Msg 1778. Then Msg 1750, and dbo.LabResult isn’t created at all. The fix is the parent’s type, int, while the table’s own key stays bigint:
CREATE TABLE dbo.LabResult ( LabResultId bigint IDENTITY(1, 1) NOT NULL CONSTRAINT PK_LabResult PRIMARY KEY, AdmissionId int NOT NULL, SampleId uniqueidentifier NOT NULL, TestCode varchar(10) NOT NULL, Value decimal(9, 3) NOT NULL, Unit varchar(20) NOT NULL, TakenAt datetime2(0) NOT NULL, IsCritical bit NOT NULL, CONSTRAINT FK_LabResult_Admission_AdmissionId FOREIGN KEY (AdmissionId) REFERENCES dbo.Admission (AdmissionId) );

Where mixed types are allowed, as in a join of an int column to a bigint one, SQL Server makes an implicit conversion: the type with the lower data type precedence is converted to the other. A foreign key gets no such conversion, so the key’s type, chosen once, becomes the type of every column that points at it.
How ERDsmith helps
In ERDsmith a column’s type is part of the model you draw, not something added when the script is written:
- With Types on, each column shows its type in the box, so a
floatamong thedecimalamounts or abigintbeside anintkey stands out. LabResult.AdmissionIdis never typed by hand: the line fromdbo.Admissiongives itint, so thebigintmismatch SQL Server refuses can’t be drawn, and wideningAdmissionIdtobigintis one edit on Admission thatInvoiceandLabResultfollow.- A type the project’s SQL Server version doesn’t have, such as
jsonorvectoron an older version, is an error. - An identity on a type that can’t take one, such as
uniqueidentifier, is an error (Msg 2749), and atext,ntextorimagecolumn gets a warning to use its replacement.