Wednesday, January 4, 2017

                                   Date/Time Datatypes

Date/Time Datatypes in SQL Server (Transact-SQL):
Data Type Syntax
Maximum Size
Explanation
(if applicable)
DATE
Values range from '0001-01-01' to '9999-12-31'.
Displayed as 'YYYY-MM-DD'
DATETIME
Date values range from '1753-01-01 00:00:00' to '9999-12-31 23:59:59'.
Time values range from '00:00:00' to '23:59:59:997'
Displayed as 'YYYY-MM-DD hh:mm:ss[.mmm]'
DATETIME2(fractional seconds precision)
Date values range from '0001-01-01' to '9999-12-31'.
Time values range from '00:00:00' to '23:59:59:9999999'.
Displayed as 'YYYY-MM-DD hh:mm:ss[.fractional seconds]'
SMALLDATETIME
Date values range from '1900-01-01' to '2079-06-06'.
Time values range from '00:00:00' to '23:59:59'.
Displayed as 'YYYY-MM-DD hh:mm:ss'
TIME
Values range from '00:00:00.0000000' to '23:59:59.9999999'
Displayed as 'YYYY-MM-DD hh:mm:ss[.nnnnnnn]'
DATETIMEOFFSET(fractional seconds precision)
Date values range from '0001-01-01' to '9999-12-31'.
Time values range from '00:00:00' to '23:59:59:9999999'.
Time zone offset range from -14:00 to +14:00.
Displayed as 'YYYY-MM-DD hh:mm:ss[.nnnnnnn]' [{+|-}hh:mm]

                                                                                                                                        

                                      String Datatypes

The following are the String Datatypes in SQL Server (Transact-SQL):

Data Type Syntax

Maximum     Size    

                            Explanation

CHAR(size)

Maximum size of 8,000 characters.

Where size is the number of characters to store. Fixed-length. Space padded on right to equal size characters. Non-Unicode data.

VARCHAR(size) or VARCHAR(max)

Maximum size of 8,000 or max characters.

Where size is the number of characters to store. Variable-length. If max is specified, the maximum number of characters is 2GB. Non-Unicode data.

TEXT

Maximum size of 2GB.

Variable-length. Non-Unicode data.

NCHAR(size)

Maximum size of 4,000 characters.

Fixed-length. Unicode data.

NVARCHAR(size) or NVARCHAR(max)

Maximum size of 4,000 or max characters.

Where size is the number of characters to store. Variable-length. If max is specified, the maximum number of characters is 2GB. Unicode data.

NTEXT

Maximum size of 1,073,741,823 bytes.

Variable length. Unicode data.

BINARY(size)

Maximum size of 8,000 characters.

Where size is the number of characters to store. Fixed-length. Space padded on right to equal size characters. Binary data.

VARBINARY(size) or VARBINARY(max)

Maximum size of 8,000 or max characters.

Where size is the number of characters to store. Variable-length. If max is specified, the maximum number of characters is 2GB. Non-Binary data.

IMAGE

Maximum size of 2GB.

Variable length . Binary data.

                                                SQL SERVER DATA TYPES


TRANSACT SQL  DATA TYPES  

                                                       Numeric Datatypes

Data Type Syntax
Maximum Size
Explanation
BIT
Integer that can be 0, 1, or NULL.

TINYINT
0 to 255

SMALLINT
-32768 to 32767

INT
-2,147,483,648 to 2,147,483,647

BIGINT
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

DECIMAL(f,l)
f defaults to 18, if not specified.
l defaults to 0, if not specified.
Where f is the total digits and l is the number of digits after the decimal.
DEC(f,l)
f defaults to 18, if not specified.
l defaults to 0, if not specified.
Where f is the total digits and l is the number of digits after the decimal.

This is a synonym for the DECIMAL datatype.
NUMERIC(f,l)
f defaults to 18, if not specified.
l defaults to 0, if not specified.
Where f is the total digits and l  is the number of digits after the decimal.

This is a synonym for the DECIMAL datatype.
FLOAT(val)
Floating point number.
val defaults to 53, if not specified.
Where val is the number of number of bits to store in scientific notation.
REAL
Equivalent to FLOAT(24)

SMALLMONEY
- 214,748.3648 to 214,748.3647

MONEY
-922,337,203,685,477.5808 to 922,337,203,685,477.5807


(DCL) Data Control Language : 


1-Data Control Language is used to define database access privileges for users.
2-Data Control Language mostly used in corporate sector.


Basically two main commands are used in DCL :

1-Grant :With the help of "Grant" command we give  database access privileges to the user.
2-Revoke:The "Revoke" command removes user access rights or privileges to the database objects.


Transaction Control Language(TCL) : 

1-Transaction Control Language play main role in Sql.
2-TCL  statements are used to manage changes made by DML Statements .
3-It allows statements to be grouped together into logical transaction.



Tuesday, January 3, 2017


Data Definition Language(DDL) :

Data Definition language is used for creating database structure or database schema.
There are many DDL commands in Sql.

1-Create : Create command is used to create database.

2-Alter : Alter Command is used  for altering  database or table structure.

3-Truncate : Truncate  command is used to delete all data from database table.It delete all data   with     blank space .

4-Comment: Comment command are used for add comments to data dictionary.

5-Rename: Rename command are used for rename object name.



Data Manipulation Language(DML) :


DML is used for insertion,deletion,updation and managing information or data  from the database schema or database objects.

There are lots of DML commands in sql :--


1-Insert : Using insert command we can insert data into database object or database table

2-Update :Using update command we can update existing  data into database object or database table

3-Delete : With the help of delete command we can delete data from the database object or table.

4-Select : Select   command is  used to retrieve data from the database objecte or table.

 What Is Database In Short?

1- Database is designed to offer a ,mechanism for storing ,managing & retrieving 
     information.

2-Database is a structured collection of data & records that is stored in tables.

3-Sql is stands for "Structured Query Language".

4-Sql is a non procedural language.

5-Sql statements are used to perform  many task such as Updation,Deletion,Insertion
     of  data  in the database.   

6.According to ANSI(American National Standard Institute) "Sql Is A Standard Language 
    for relational database
  
There are few main category of Sql Database

1- (DDL)Data Definition Language .
2-(DML)Manipulation Language  .
3-(DCL)Data Control Language  .
4-(TCL)Transact Control Language . 
5-(DQL)Data Query Language .