0% found this document useful (0 votes)
26 views27 pages

SQL DATATYPES

The document provides a comprehensive overview of various SQL data types, their characteristics, and usage, including fixed and variable length types, storage sizes, and formats for date and time. It also covers operations such as DELETE, TRUNCATE, and the use of temporary tables, views, and stored procedures, highlighting their limitations and advantages. Additionally, it includes examples of employee and department data, showcasing how to structure and manipulate this information within a database context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views27 pages

SQL DATATYPES

The document provides a comprehensive overview of various SQL data types, their characteristics, and usage, including fixed and variable length types, storage sizes, and formats for date and time. It also covers operations such as DELETE, TRUNCATE, and the use of temporary tables, views, and stored procedures, highlighting their limitations and advantages. Additionally, it includes examples of employee and department data, showcasing how to structure and manipulate this information within a database context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Features Char nchar varchar Nvarchar

Fixed Length YES YES NO NO


Variable Length NO NO YES YES
unicode YES NO YES NO
non-unicode NO YES NO YES
size 8000 4000 8000 4000
S R I N I V A S
20
I
Data type Format

time hh:mm:ss[.nnnnnnn]
date YYYY-MM-DD
smalldatetime YYYY-MM-DD hh:mm:ss
datetime YYYY-MM-DD
datetime2 YYYY-MM-DD
datetimeoffset hh:mm:ss[.nnn]
YYYY-MM-DD
hh:mm:ss[.nnnnnnn]
hh:mm:ss[.nnnnnnn]
[+|-]hh:mm
Range Accuracy

00:00:00.0000000 through 100 nanoseconds


0001-01-01 through
23:59:59.9999999 9999-12- 1 day
1900-01-01
31 through 2079-06- 1 minute
1753-01-01
06 through 9999-12- 0.00333 second
0001-01-01
31 00:00:00.0000000 100 nanoseconds
0001-01-01 00:00:00.0000000 100 nanoseconds
through 9999-12-31
through 9999-12-31
23:59:59.9999999
23:59:59.9999999 (in UTC)
Storage size
(bytes)

3 to 5
3
4
8
6 to 8
8 to 10
Data type Length
bigint 8
int 4
smallint 2
tinyint 1
bit
decimal(preci 1 bit
sion,
money scale) 8
smallmoney 4
float(n)
Description
Integer from -2^63 (-9 223 372 036 854 775 808) to 2^63-1 (9
223 372from
Integer 036 -2^31
854 775 (-2807)
147 483 648) to 2^31-1 (2 147 483 647)
Integer from -2^15 (-32 768) to 2^15-1 (32 767)
Integer from 0 to 255
Integer
Numeric 0data
Financial or 1.type
data type with
fromfixed
-2^63precision and203
(-922 337 scale
685(accuracy
477.5808) 1- to
38, 18 by
2^63-1
Numeric default
(922
Financial data
data 337 and
203
type
type from
withscale
685 0-p,
-2^31
float 0 by default).
477.5807)
(-214 with
precision, the precision
748.3648)
where tothe
n is of one
2^31-1
number(214
ten-thousandth
748.3647)
of mantis bits unit.precision
with(1-24,
the accuracyofofone ten-thousandth
7 digits, unit.and 25-
size of 4 bytes
53, accuracy of 15 digits and size of 8 bytes).
DELETE
DML
You can use
Structure willwhere clausesame
be remains to
delete specific
, but data records
will be deleted
Performance will be slow compare to truncate
Yes, we can rollback data

STID
1
2
3
4
5
6
TRUNCATE DROP
DDL
You can not
Structure willuse
bewhere clause
remains sameto DDL
delete specific
, but data records
will be deleted It will drop the structure
Performance will be fast compare to delete
Yes, we can rollback data

NAME
AAA
BBB
CCC
DDD
EEE
FFF
EMPIDNAMEMANAGERID EMPID
1NAVEE 3 1
2YAKEN 1 2
3SRINI NULL 3
4VENKA 2 4
5KAMA 2 5

EMPIDEMPLOYEEMANAGERNAME
1NAVEEN SRINIVAS
2YAKENDERNAVEEN
3SRINIVAS NULL
4VENKATESYAKENDER
5KAMAL YAKENDER
NAME MANAGERID
NAVEEN 3
YAKENDER 1
SRINIVAS NULL
VENKATESH 2
KAMAL 2
EMPID NAME SAL DEPT
1 JOHN 50000 D002
2 JANE 30000 D003
3 JIM 40000 D002
4 JILL 70000 D001
5 JOE 60000 D003

6 JACK 90000 D001


7 JERRY 80000 D003
8 JENNY 80000 D001

SALEID SALEDATE SALEAMOUNTPREVIOUSDAY


1 1/1/2023 50000 NULL
2 1/2/2023 30000 50000
3 1/3/2023 40000 30000
4 1/4/2023 70000 40000
5 1/5/2023 60000 70000
EMPID
SALEID SALEDATE SALEAMOUNTNEXTDAY
1 1/1/2023 50000 30000
2 1/2/2023 30000 40000
3 1/3/2023 40000 70000
4 1/4/2023 70000 60000
5 1/5/2023 60000 NULL
Feature Derived Table
Scope Single query only
Definition Inline in the FROM clause
Reusability No
Storage Memory (inline processing)
Can be Indexed? No
Use case Simple, one-time subquery
SELECT

DEPTID DEPTNAME
D001 IT
D002 HR
D003 SALES
CTE
Single query (can be reused within)
WITH clause before the query
Yes (within the query)
Memory (inline processing)
No
Readability, recursion, reusable logic
INSERT, UPDATE,DELETE AND SELECT

EMPID
1
2
3
4
5
6
7
8
Temporary Table
Session or batch-level
Created with SELECT INTO or CREATE TABLE
Yes (within the session)
Disk (in tempdb database)
Yes
Complex operations, large intermediate result sets,
multiple queries

NAME
JOHN
JANE
JIM
JILL
JOE
JACK
JERRY
JENNY
SAL DEPT
50000 D002
30000 D003
40000 D002
70000 D001
60000 D003
90000 D001
80000 D003
80000 D001
ID NAME EMAIL AGE
1AAA [email protected] 30
2BBB [email protected] 35
3CCC [email protected] 28
4DDD [email protected] 32
5EEE [email protected] 38
6FFF [email protected] 26
7GGG [email protected] 40
8HHH [email protected] 38
CITY SAL
HYD 4000
BLR 6000 4 2
HYD 8000
PUN 7000 1,7
BLR 4000
PUN 3000
HYD 5000
PUN 7000
ID Name Gender DEPT
1 SRINIVAS Male IT
2 NAVEEN Male HR
3 YAKENDER Male IT
4 REDDY Male HR
5 KAMAL Male SALES
6 RAJASHEKAR Male SALES
7 KAVITHA Female IT
8 Reenu Female HR
9 SARITHA Female SALES
D Name Gender Salary Hiredate
1 SRINIVAS Male 30000 11/5/2017
2 NAVEEN Male 50000 11/5/2017
3 YAKENDER Male 40000 12/12/2017
4 REDDY Male 45000 12/15/2017
5 KAMAL Male 50000 1/12/2018
6 RAJASHEKAR Male 25000 2/26/2018
7 KAVITHA Female 30000 2/18/2018
8 Reenu Female 40000 9/19/2017
9 SARITHA Female 25000 4/4/2018
ID Name DOB
1 AAA 8/26/1994
2 BBBB 8/19/2013
3 CCC 1/9/2016
4 DDD 11/18/1982
VIEW
SIMPLE QUERY
COMPLEX QUERY

USING VIEW :--


INSERT DATA INTO TABLE
UPDATE DATA INTO TABLE
DELETE DATA INTO TABLE
READING DATA

LIMITATIONS
IT WILL NOT PARAMETERS
IT WILL TEMP TABLE
IT WILL SUPPORT PROGRAMMING
FUNCTION
IT WILL SUPPORT ONLY SELECT(READING) DATA

NO INSERT
NO UPDATE
NO DELETE
IT IS NOT GOING TO CHANGE BASE TABLES

COMPLEX ARITHMATICAL OPS


PROGRAMMING
USE VARIABLES
FUNCTIONS
INPUT PARAMETER

LIMITATION
IT WILL NOT SUPPORT OUTPUT PARAMETER
NO I/U/D TABLE DATA
CAN CALL SP INSIDE FN
ADV :--
WE CAN CALL UDF AS PART SELECT/UPDATE/DELETE
STORED PROCED
DML (I/U/D/S)
DDL (C/D/A)
PROGRAMMING
INSIDED SP WE CAN CALL ANOTHER SP
CAN ALSO THE FUNCTION IN SP
USE CURSORS

CACHE EXECUTION PLAN AND RE-USE NEXT TIMES


SP AS FASTER
SP SUPPORT TRAN
IT WILL SUPPORT PARAMETERS
INPUT
OUTPUT
ERROR HANDLING

LIMITATIONS
EXEC/ EXECUTE <SP NAME>
CAN NOT CALL SP AS PART OF SELECT/INSERT/UPDATE/DELETE

DATE/DELETE
EMPID EmployeeName Gender Salary DeptName
1 aaa MALE 5000 IT
2 bbb FEMALE 3000 HR
3 ccc MALE 7000 IT
4 ddd FEMALE 8000 HR
5 eee MALE 4000 IT

DEPTNAME Employee EMPID


IT SAM,MIKE,MICK 1
HR PAM 2
3
4
5
DEPTNAME Employee1 Employee2 Employee3
IT Sam mike mick
HR Pam
PK FK
DEPTID DEPTNAME DEPTID EMPNAME
1 IT 1 Sam
2 HR 1 mike
1 mick
2 PAM
EMPID EmployeeName Gender Salary DeptName
1 aaa MALE 5000 IT
2 bbb FEMALE 3000 HR
3 ccc MALE 7000 IT
4 ddd FEMALE 8000 HR
5 eee MALE 4000 IT
DeptHead DeptLocation EMPID Employee
JOHN LONDON 1 aaa
MIKE SYDNEY 2 bbb
JOHN LONDON I/U/D 3 ccc
MIKE SYDNEY 4 ddd
JOHN LONDON 5 eee

FK PK
EmployeeNGender Salary DEPTID DEPTIDDeptName
aaa MALE 5000 1 1 IT
bbb FEMALE 3000 2 2 HR
ccc MALE 7000 1
ddd FEMALE 8000 2
eee MALE 4000 1

PK
DeptHead DeptLocation DEPTIDDeptName
JOHN LONDON 1 IT
MIKE SYDNEY 2 HR
JOHN LONDON
MIKE SYDNEY
JOHN LONDON EMPID Employee
1 aaa
2 bbb
3 ccc
4 ddd
5 eee
Gender Salary Annual salary DeptName
MALE 5000 60000 1
FEMALE 6000 72000 2
MALE 7000 84000 1
FEMALE 8000 96000 2
MALE 4000 48000 1

DeptHead DeptLocation
JOHN LONDON
MIKE SYDNEY

DeptHead DeptLocation
JOHN LONDON
MIKE SYNDEY
FK
Gender Salary DEPTID
MALE 5000 1
FEMALE 3000 2
MALE 7000 1
FEMALE 8000 2
MALE 4000 1

You might also like