SQL Server Notes
SQL Server Notes
Database:- Is a place where we can store the data and also retrive ( taking) the
data whenever you want.
Types of DBMS:-
1. NDBMS:- Network DBMS ( it got failure that it can't store all types of data)
2. HDBMS:- Hierarchical DBMS ( it also got failure)
3. RDBMS:- Relational Database Management System
It can store any type of data & it is very easy to write & understand the syntax.
Microsoft:- MSSQL
MySQL:-
Oracle SQL:- Oracle
Postgre SQL
T-SQl
NEteza
Teradata
RDBMS:- Relational Database Management System which is used to store & Retrive the
data & Sql is the language used to communicate with the RDBMS.
SQL Server(RDBMS) which is invented by Microsoft & we are going to discuss with MS-
SQL
SQL server:- RDBMS
Ms-SQL:- Language
SSMS:- Application
In a single object they can install & maintain upto 50 servers. Each server is
like a each business.
Each server installation is called as 'Instance' & one instance won't spill the
data for another instance.
The data will be storing inside the database but not in the form of the database
Then how?
The data inside the SQL server instance database in the form of Rows & Columns ==>
Table
To create a database:-
Create database "Data Analyst Training"
To Create a Table:-
First you needs to mention in which database the tables needs to be created so, for
this:-
Use Databasename
Create Table Tablename
(
Table structure:- Column names, Column Datatype
)
Number
1.Whole Number:- without decimals
a.tinyint:- o to 255(1kb)
b.smallint:- (2kb)
c.int(4kb)
d.bigint
2.Decimal number:- with decimals
a.decimal:- 38 digits ---> 2111122474.93
b.Numeric:- > 38
3.Approximate:- exact values
a.Float---> 4bytes --> 23.133333333333
b.real----> 8bytes ---> 23.13333333333333333333333333333333333
Binary:- hexadecimal(1,0)
If you are updating/inserting any file format data(image, video, audio), the Sql
engine will converts this files and stores these files in Binary datatype. ---->
2GB
Constraints:- these constraints will/ used to validate the data in Sql server
1. NULL, NOT NULL
2. Default
3. Primary Key
4. Foreign Key
5. Unique Key
6. Check
If there is already one primary key column exists there will be no second primary
key column,
But if there is another unique data maintaining columns those all columns will
called as Unique Keys.
Foreign Key:- if the primary key in one table is passing from that table to
another/ Opposite table the same primary key will change its name as a foreign key.
If you are connecting two tables using Primary key and foreign key is called as
relationships.
any database is supporting Relationships that database is called as Relational
Database management system.
Mysql
Oraclesql
Neteza
Teradata
MsSQL
2. 1-M:-
If One table Primary Key acts as a foreign key in opposite table but the same
opposite table primary key can't act as a foreign key in the first table.
:- 2 Tables, 2 Pk's, 1 FK
3. M-M:-
To Build The M-to- M relationship we needs to maintain the Foreign keys from
both the tables in a seperate table and by using this seperate table we can build
m-to-m relationship and this seperate table is called as a bridge Table.
Syntax :-
Cascade Features:-
Cascade Features is one of the Option BY SSMS to make sure the Data in a Primary
key will be updating in Foreign Key everytime.
Automatically the data will be updated and deleted the same information in FK also
be reflected.
Data Warehousing:-
SQL Commands:-
Database:- it is a place where it will be holding all the transactions we are doing
in SQL server.
There are two types of databases in SQL Server:-
1. SYSTEM Databases:- created by SSMS by default
a. Master:- Every Password, Usernames, Instance details
b. Model:- Template of the SSMS
c. msdb:- Alerts & Backups
4. Tempdb:- Calculations, Creations at the time will be stored temporily.
While Creating The Database by User the SSMS will be saving this Database data in
two File Types:-
1--> .mdf (Metadata file) ---> Every data will be stored in this file
2--> .ldf (Log Data File) ----> every time while creating the data will be stored
in this file.
Comments:- While writing SQL queries if you want to store some decriptions/
Comments you needs to use:--
/*
This is rubicon infotech Data analyst Sessions
By Durga Rao
Classes availabe here:- EXCEL, SQL, Power BI
*/
Use sample_Training
go
/*
If you wants to create a table first you needs to maintain
some syntax means you needs to create table structure along
with the table,
Table structure:--- Column names, Datatypes of column
*/
/*
Syntax of table creation:-
Create Table <Table Name>
(
Columnname datatype constraint,
Columnname2 datatype Constraint
)
*/