- The data type of a column defines what value the column can hold: integer, character, money, date and time, binary,Image and so on.
- Each column in a database table is required to have a name and a data type.
- An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data.
Most used SQL data types :
- VARCHAR(size) - to store character string data
- INT(size) - to store numeric data
- BIGINT(size) - to store numeric data
- FLOAT(size,d) - numeric data with floating decimal point
- DOUBLE(size,d) - A large number with a floating decimal point
- DATE - to store date
- DATETIME -to store date with time
- nvarchar - to store Unicode string (we can give size as MAX for unlimited length)
- varbinary - to store binary string
- Image - to store encoded image
Create Database and Tables
To create database ->Database-> Create New in sql server management studio OR use below query
CREATE DATABASE databasename
To create table ->Database->Tables-New table OR use below query
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... )
SQL Select , Select distinct, Select top statements
SQL select statement - is used to select data from a database
SELECT column1, column2, ... FROM table_name;
The SELECT DISTINCT statement - is used to return only distinct (different) values.
SELECT DISTINCT column1, column2, ... FROM table_name
Select top statement - is use to get top / limited records from database table
SELECT TOP number(s)(of records we want) FROM table_name