In Microsoft SQL Server (MSSQL), there are various data types that you can use to define columns in your database tables. Here is a list of some commonly used data types in MSSQL along with examples:
1. Integer Types:
- INT: Integer data type (4 bytes).
CREATE TABLE ExampleTable (
ID INT
);
- BIGINT: Big integer data type (8 bytes).
CREATE TABLE ExampleTable (
ID BIGINT
);
2. Numeric Types:
- DECIMAL: Fixed precision and scale numeric data type.
CREATE TABLE ExampleTable (
Price DECIMAL(10, 2)
);
- FLOAT: Floating-point number data type.
CREATE TABLE ExampleTable (
Price FLOAT
);
3. Character Types:
- VARCHAR: Variable-length character data type.
CREATE TABLE ExampleTable (
Name VARCHAR(50)
);
- CHAR: Fixed-length character data type.
CREATE TABLE ExampleTable (
Initial CHAR(1)
);
4. Text Types:
- TEXT: Variable-length character data type for large text values.
CREATE TABLE ExampleTable (
Description TEXT
);
5. Date and Time Types:
- DATE: Date data type.
CREATE TABLE ExampleTable (
BirthDate DATE
);
- DATETIME: Date and time data type.
CREATE TABLE ExampleTable (
LastUpdate DATETIME
);
6. Boolean Type:
- BIT: Boolean data type.
CREATE TABLE ExampleTable (
IsActive BIT
);
7. Binary Types:
- BINARY: Fixed-length binary data type.
CREATE TABLE ExampleTable (
BinaryData BINARY(10)
);
- VARBINARY: Variable-length binary data type.
CREATE TABLE ExampleTable (
ImageData VARBINARY(MAX)
);
8. Unique Identifier Type:
- UNIQUEIDENTIFIER: Globally unique identifier data type.
CREATE TABLE ExampleTable (
GUIDColumn UNIQUEIDENTIFIER
);
These are just some of the data types available in MSSQL. Depending on your requirements, you may choose different data types to define columns in your database tables.
No comments:
Post a Comment