SQL Server
SQL SERVER
Basic Relational Database Design
-
A relational database uses a
structure that allows us to identify and access data in the database. Often,
data in a relational database is organized into tables.
-
Benefit of relational database
A) Simplicity
B)
Flexibility
C)
Ease of data retrieval
D) Normalization
E)
Data integrity
* It gives the user and programmers a way to create
, retrieve, update, and manage data.
Ex- SQL Server, My SQL
Database Design…..
The process of
producing a Database Model that contains a
detailed description of the logical and physical choice
that can used to create a database.
Tables-
Key – Uniquely identify records in a table.
- Identify relationships between
tables.
Fields-
Character string -
char, vchar, text, nchar, nvarchar, ntext
Numbers- int, bigint, smallint, bit, tinyint, float,
dateTime, date
, time , smalldatetime,
Binary – binary, varbinary,
Img -img
Relationships in database-
-
One-to-one
-
One-to-many
-
Many-to-many
Normal Form
-
Process or approach used to organize
data efficiently in database.
·
Avoid data redundancy
·
Ensure that data is logically stored
-
Type of normal forms-
·
First normal form
·
Second normal form
·
Third normal form
- first normal form
* Only atomic values
* No repeating groups
* Primary key for
each table
- Second normal form
* The table should be
in 1NF (normal form).
* No partial
dependency
- Third normal form
* The table should be
in 2NF.
* All non – PK fields are dependent on the PK (primary
key).
SQL SERVER
What is data?
- * Fact related to an object.
· What is database?
- * Database is systematic collection of data.
- * Database support storage and manipulation of data.
- * Database makes data management easy
What is SQL SERVER?
- * SQL SERVER is a relational database management system, or RDBMS.
- * A database management system is a program which enables its user to access database, manipulate data , reporting / representation of data.
-
Editions includes-
· Express (Free)
· Developer (free – for testing and development)
· Standard (License – Production)
· Enterprise (License – Production)
-
What
is SQL?
· SQL is standard language for storing,
manipulating and retrieving data in databases.
· Short for Structured Query Language
Create a database in SQL
-
CREATE DATABASE SampleDB
-- remove database
drob
database
Table: -
Creating and working with tables
The GROUP BY
statement groups rows that have the same values into summary rows, like "find the number of customers in each country".
The GROUP BY
statement is often used with aggregate functions (COUNT()
, MAX()
, MIN()
, SUM()
, AVG()
) to group the result-set by one or more columns.
Different Types of SQL JOINs
Here are the different types of the JOINs in SQL:
(INNER) JOIN
: Returns records that have matching values in both tablesLEFT (OUTER) JOIN
: Returns all records from the left table, and the matched records from the right tableRIGHT (OUTER) JOIN
: Returns all records from the right table, and the matched records from the left tableFULL (OUTER) JOIN
: Returns all records when there is a match in either left or right table
Join to database-
select
* from car_db.cars
inner join car_db.category on
car_db.category.CategoryId =
car_db.cars.S_no
or we can write as
select * from car_db.cars c
inner join car_db.category cat on cat.CategoryId = c.S_no
Left join
Right join
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key
- Table can have multiple candidate keys.
- Among the set of candidate, one candidate key is chosen as Primary Key.
- A table can have only one primary key and one candidate key can select as a primary key.
- The primary key should be chosen such that its attributes are never or rarely changed.
- Cannot contain “NULL”.
- Primary key field contain a clustered index.
- Unique key is similar to primary key but unique key field can contain a “Null” value but primary key doesn’t allow “Null” value.
- Unique field contain a non-clustered index.
- Foreign key is used to generate the relationship between the tables.
- A foreign key can accept null and duplicate value.
Comments
Post a Comment