Course Content
Joins
0/1
Stored procedure
0/1
Database Design
0/1
Querying and Reporting
0/1
Data Validation and Constraints
0/1
Performance Optimization
0/1
Indexing strategies and best practices
0/1
Query Optimization Techniques
0/1
Analyzing query execution plans
0/1
Security and Access Control
0/1
Advanced Topics (optional, based on project needs)
0/1
SQL/SQL Server
About Lesson

DATA TYPES IN SQL

  1. Numeric Data Types

 

  • Integer: A whole number without a decimal point.
  • Decimal: A number with a decimal point.
  • Floating-point: A number with a decimal point and a fractional part.
  1. Character Data Types

  • Char: A fixed-length character string.
  • Varchar: A variable-length character string.
  • Nchar: A fixed-length Unicode character string.
  • Nvarchar: A variable-length Unicode character string.
  1. Date and Time Data Types

  • Date: A date without a time.
  • Time: A time without a date.
  • DateTime: A date and time.
  • Smalldatetime: A date and time with a precision of 3.33 milliseconds.
  • Datetime2: A date and time with a precision of 7.00 milliseconds.
  1. Other Data Types

 

  • Binary: A binary string.
  • Varbinary: A variable-length binary string.
  • Image: A large binary string.
  • UniqueIdentifier: A unique identifier.
  • Cursor: A pointer to a set of rows.
  • Rowversion: A value that changes whenever a row is updated.
  • XML: An XML document.

The data type of a column defines what value the column can hold. For example, an integer column can only hold whole numbers, while a varchar column can hold any string of characters.

When you create a table, you must specify the data type for each column. For example, the following statement creates a table with two columns:

CREATE TABLE customers (

  id INT,

  name VARCHAR(255)

);

The id column is an integer column, and the name column is a varchar column with a maximum length of 255 characters.

You can also change the data type of a column after the table has been created. For example, the following statement changes the data type of the name column to nvarchar:

ALTER TABLE customers

ALTER COLUMN name NVARCHAR(255);