SQL Database Notes
SQL Database Notes
SQL is the standard language for Relational Database System. All the Relational
Database Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase,
Informix, Postgres and SQL Server use SQL as their standard database language.
Allows users to define the data in a database and manipulate that data.
Allows to embed within other languages using SQL modules, libraries & pre-
compilers.
1978 − IBM worked to develop Codd's ideas and released a product named
System/R.
WHAT IS FEILD?
Every table is broken up into smaller entities called fields. The fields in the CUSTOMERS
table consist of ID, NAME, AGE, ADDRESS and SALARY.
A field is a column in a table that is designed to maintain specific information about every
record in the table.
WHAT IS COLUMN?
A column is a vertical entity in a table that contains all information associated with a specific
field in a table.
SQL CONSTRAINTS?
Constraints are the rules enforced on data columns on a table. These are used to limit the
type of data that can go into a table. This ensures the accuracy and reliability of the data in
the database.
Following are some of the most commonly used constraints available in SQL
NOT NULL Constraint − Ensures that a column cannot have a NULL value.
DEFAULT Constraint − Provides a default value for a column when none is specified.
UNIQUE Constraint − Ensures that all the values in a column are different.
CHECK Constraint − The CHECK constraint ensures that all values in a column satisfy
certain conditions.
INDEX − Used to create and retrieve data from the database very quickly.
Data Integrity
Domain Integrity − Enforces valid entries for a given column by restricting the type,
the format, or the range of values.
Referential integrity − Rows cannot be deleted, which are used by other records.
User-Defined Integrity − Enforces some specific business rules that do not fall into
entity, domain or referential integrity.
Database Normalization
Eliminating redundant data, for example, storing the same data in more than one
table.
MS SQL Server
T-SQL
ANSI SQL
History
1989 - Microsoft, Sybase, and Aston-Tate release SQL Server 1.0 for OS/2.
1990 - SQL Server 1.1 is released with support for Windows 3.0 clients.
2001 - Microsoft releases XML for SQL Server Web Release 1 (download).
2002 - Microsoft releases SQLXML 2.0 (renamed from XML for SQL Server).
Features
High Performance
High Availability
Database mirroring
Database snapshots
CLR integration
Service Broker
DDL triggers
Ranking functions
XML integration
TRY...CATCH
Database Mail
tinyint 0 255
Bit 0 1
Note − Here, datetime has 3.33 milliseconds accuracy where as smalldatetime has 1
minute accuracy.
char
1
Maximum length of 8,000 characters.( Fixed length non-Unicode
characters)
varchar
2
Maximum of 8,000 characters.(Variable-length non-Unicode data).
3 varchar(max)
Maximum length of 2E + 31 characters, Variable-length non-Unicode
data (SQL Server 2005 only).
text
4
Variable-length non-Unicode data with a maximum length of
2,147,483,647 characters.
nchar
1
Maximum length of 4,000 characters.( Fixed length Unicode)
nvarchar
2
Maximum length of 4,000 characters.(Variable length Unicode)
nvarchar(max)
3
Maximum length of 2E + 31 characters (SQL Server 2005 only).(
Variable length Unicode)
ntext
4
Maximum length of 1,073,741,823 characters. ( Variable length
Unicode )
1 binary
Maximum length of 8,000 bytes(Fixed-length binary data )
varbinary
2
Maximum length of 8,000 bytes.(Variable length binary data)
varbinary(max)
3
Maximum length of 2E + 31 bytes (SQL Server 2005 only). ( Variable
length Binary data)
image
4
Maximum length of 2,147,483,647 bytes. ( Variable length Binary
Data)
sql_variant
1
Stores values of various SQL Server-supported data types, except text,
ntext, and timestamp.
timestamp
2
Stores a database-wide unique number that gets updated every time a
row gets updated
uniqueidentifier
3
Stores a globally unique identifier (GUID)
4 xml
Stores XML data. You can store xml instances in a column or a variable
(SQL Server 2005 only).
cursor
5
Reference to a cursor object
table
6
Stores a result set for later processing