A constant is a symbol that represents a specific data value. The format of a constant depends on the data type of the value it represents. Constants are also called literals. Some examples of constants are:
'O''Brien'
'The level for job_id: %d should be between %d and %d.'
N'Michél'
0x12Ef
0x69048AEFDD010E
'April 15, 1998'
'04/15/98'
'14:30:24'
'04:24 PM'
1894
2
1894.1204
2.0
101.5E5
0.5E-2
$12
$542023.14
0xff19966f868b11d0b42d00c04fc964ff
'6F9619FF-8B86-D011-B42D-00C04FC964FF'
For numeric constants, to specify the sign of the numeric value use the unary + and - operators:
+$156.45
-73.52E8
-129.42
+442
In Transact-SQL, constants can be used in many ways. Here are some examples:
SELECT Price + $.10
FROM MyTable
SELECT *
FROM MyTable
WHERE LastName = 'O''Brien'
SET @DecimalVar = -1200.02
UPDATE MyTable
SET Price = $99.99
WHERE PartNmbr = 1234
INSERT INTO MyTable VALUES (1235, $88.88)
PRINT 'This is a message.'
IF (@@SALESTOTAL > $100000.00)
EXECUTE Give_Bonus_Procedure
Constants | INSERT |
Expressions | LIKE |
Operators | |
ALTER TABLE | RAISERROR |
CREATE TABLE | UPDATE |
DELETE | WHERE |