SQL NavigationSSMS Updated-2
SQL NavigationSSMS Updated-2
🞆 SQL Server Management Studio (SSMS) is the main administrative console for SQL Server installations. It provides
you with a graphical "birds-eye" view of all of the SQL Server installations on your network. You can perform high-level
administrative functions that affect one or more servers, schedule common maintenance tasks or create and modify the
structure of individual databases.
🞆 SQL Profiler provides a window into the inner workings of your database. You can monitor many different event types
and observe database performance in real time. SQL Profiler allows you to capture and replay system "traces" that log
various activities. It's a great tool for optimizing databases with performance issues or troubleshooting particular
problems. As with many SQL Server functions, you can access SQL Profiler through SQL Server Management Studio.
🞆 Monitoring Tool
🞆 Used for Performance Tuning
🞆 Uses Traces – an event monitoring protocol
SQL Server 2012
🞆 SQL Server Agent allows you to automate many of the routine administrative tasks that consume database
administrator time. You can use SQL Server agent to create jobs that run on a periodic basis, jobs that are triggered by
alerts and jobs that are initiated by stored procedures. These jobs may include steps that perform almost any
administrative function, including backing up databases, executing operating system commands, running SSIS
packages and more.
🞆 SQL Server Integration Services (SSIS) provide an extremely flexible method for importing and exporting data
between a Microsoft SQL Server installation and a large variety of other formats. It replaces the Data Transformation
Services (DTS) found in earlier versions of SQL Server.
SQL Server 2012
🞆 SQL Server Configuration Manager is a snap-in for the Microsoft Management Console (MMC) that allows you to
manage the SQL Server services running on your servers. The functions of SQL Server Configuration Manager
include starting and stopping services, editing service properties and configuring database network connectivity
options.
🞆 Allows for more than one instance to be installed on a machine
🞆 First instance is called the default instance MSSQLSERVER
🞆 Other instances are called as named instances
🞆 SQL Server Configuration Manager
🞆 Allows various services associated with SQL Server to be stopped/started for each instance individually.
🞆 Has Access to the Following Services:
🞆 SQL Server Service
🞆 SQL Server Agent Service
SQL Server Management Studio (SSMS)
🞆 On the Start menu, point to All Programs > Microsoft SQL Server 2012 > SQL Server Management
Studio.
🞆 In the Connect to Server dialog box, verify the default settings, and then click Connect. To connect the
Server name box must contain the name of the computer where SQL Server is installed. If the database
engine is a name instance, the Server name box should also contain the instance name.
🞆 Select SQL Server Authentication
🞆 SA Account stands for System Administrator
SQL Server Management Studio (SSMS)
🞆 Most configuration options modified in SQL Server properties screen are available through a system-stored
procedure called sp_configure
🞆 The sp_configure procedure takes two parameters:
🞆 @configname
🞆 Name of the configuration setting to change
🞆 @configvalue
🞆 New value to assign to the specified configuration setting
SQL Server Management Studio (SSMS)
🞆 The command DBCC CHECKDB(database_name) checks the logical and physical integrity of all the objects in the
specified database. If corruption has occured for any reason, the DBCC CHECKDB command will find it, and tell you
exactly where the problem is. DBCC CHECKDB has a few optional arguments to help you fix your corrupt database.
Depending on how bad it is, you may need to use the “REPAIR_ALLOW_DATA_LOSS”, which, as the name applies,
will fix your database, but some data might get lost. You should _always_ try to recover your database using a backup
before using the “REPAIR_ALLOW_DATA_LOSS” argument.
🞆 Other corruptions which can be fixed without data loss, could be inconsistency between the table and the indexes. Let’s
say one of your nonclustered indexes for some reason miss a couple of rows – then a index rebuild will fix it. This
argument is called REPAIR_REBUILD.
🞆 DBCC CHECKDB('SBSChp4SSMS')
DBCC CHECKDB
🞆 DBCC CHECKDB validates the integrity of everything in a database. There is no need to run DBCC CHECKALLOC
or DBCC CHECKTABLE if DBCC CHECKDB either is currently or has been recently executed.
🞆 DBCC CHECKDB performs the same checking as if both a DBCC CHECKALLOC statement and a DBCC
CHECKTABLE statement were executed for each table in the database.
🞆 DBCC CHECKDB(AdventureWorks2012) GO
Relational Database(s)
🞆 A relational database organizes data in tables (or relations). A table is made up of rows and columns. A row is also
called a record (or tuple). A column is also called a field (or attribute). A database table is similar to a spreadsheet.
However, the relationships that can be created among the tables enable a relational database to efficiently store huge
amount of data, and effectively retrieve selected data.
🞆 The first step in creating a database is creating a plan that serves both as a guide to be used when implementing the
database and as a functional specification for the database after it has been implemented. The complexity and detail of a
database design is dictated by the complexity and size of the database application as well as the user population.
🞆 A well-designed database shall:
🞆 Eliminate Data Redundancy: the same piece of data shall not be stored in more than one place. This is because duplicate data not
only waste storage spaces but also easily lead to inconsistencies.
🞆 Ensure Data Integrity and Accuracy:
🞆 [TODO] more
Relational Database Design Process
🞆 Database design is more art than science, as you have to make many decisions. Databases are usually customized to
suit a particular application. No two customized applications are alike, and hence, no two database are alike.
Guidelines (usually in terms of what not to do instead of what to do) are provided in making these design decision, but
the choices ultimately rest on the you - the designer.
🞆 Step 1: Define the Purpose of the Database (Requirement Analysis)
🞆 Gather the requirements and define the objective of your database, e.g. ...
🞆 Drafting out the sample input forms, queries and reports, often helps.
🞆 Step 2: Gather Data, Organize in tables and Specify the Primary Keys
🞆 Once you have decided on the purpose of the database, gather the data that are needed to be stored in the
database. Divide the data into subject-based tables.
🞆 Choose one column (or a few columns) as the so-called primary key, which uniquely identify the each of the
rows.
SQL Database Objects
🞆 The primary key is used both to identify unique rows in a relation and to represent rows in relationships.
🞆 In the relational model, a table cannot contain duplicate rows, because that would create ambiguities in
retrieval. To ensure uniqueness, each table should have a column (or set of columns), called primary key,
that uniquely identifies every record of the table.
🞆 Most RDBMSs build an index on the primary key to facilitate fast search and retrieval.
🞆 The primary key is also used to reference other tables (to be elaborated later).
Primary Key
🞆 You have to decide which column(s) is to be used for primary key. The decision may not be straight forward
but the primary key shall have these properties:
🞆 The values of the primary key shall be unique (ie. No duplicate value). For example, customerName may not be
appropriate to be used as the primary key for the Customers table, as there could be (2) customers with the same
name.
🞆 The primary key shall always have a value. It can’t be NULL.
Relational Database Design Process
🞆 Normalization is the process of organizing data in a database that includes creating tables and establishing
relationships between the tables.
🞆 Process is used to help eliminate redundant data
🞆 Five normalization forms (NFs)
🞆 INF: Eliminate Repeating Groups
🞆 2NF: Eliminate Redundant Data
🞆 3NF: Eliminate Columns Not Dependent on Key
🞆 4NF: Isolate Independent Multiple Relationships
🞆 5NF: Isolate Semantically Related Multiple Relationships
Normalization – 1NF
🞆 First Normal Form (1NF): A table is 1NF if every cell contains a single value, not a list of values. This
property is known as atomic. 1NF also prohibits repeating group of columns such a item1, item2… Instead
you should create another table using one-to-many relationship.
🞆 The first normal form means the data is an entity format, which means the following conditions have been
met:
🞆 Eliminate repeating groups in individual tables.
🞆 Create separate table for each set of related data.
🞆 Identify each set of related data with primary key
🞆 Do not use multiple fields in a single table to store similar data.
Normalization – 2NF
🞆 Second Normal Form (2NF): A table is 2NF, if it is 1NF and every non-key column is fully dependent on
the primary key. Furthermore, if the primary key is made up of several columns, every non-key column shall
depend on the entire set and not part of it.
🞆 The second normal form ensures each attribute describes the entity.
🞆 Create separate tables for sets of values that apply to multiple records.
🞆 Relate these tables with a foreign key.
🞆 Records should not depend on anything other than a table’s primary key, including a compound key if
necessary.
Normalization – 3NF
🞆 Third Normal Form (3NF): A table is 3NF, if it is 2NF and the non-key columns are independent of each
other. In other words, the non-key columns are dependent on the primary key, only on the primary key and
nothing else. For example, suppose that we have a Products table with columns productID (primary key),
name and unitPrice. The column discount Rate shall not belong to the Products table if it is also dependent
on the unitPrice, which is not part of the primary key.
🞆 The third normal form checks for transitive dependencies.
🞆 Eliminate fields that do not depend on the key.
🞆 Values that are not part of the record’s key do not belong in the table.
🞆 In general if the contents of a group of fields apply to more than a single record, put those fields in a separate table.
Normalization – 4NF and 5NF
🞆 Un-normalized table:
Student Advisor Adv-Room Class1 Class2 Class3
1022 159-02
4123 201-01
4123 211-02
4123 214-01
Normalization - Examples
1022 159-02
Name Room Dept
4123 201-01
Jones 412 42
4123 211-02
Smith 216 32
4123 214-01
Summary
🞆 SQL Server 2012 is supported by several graphical and command prompt-based applications
🞆 The combination of Enterprise Manager and Query Analyzer allow just about every task associated with instance
management to be performed
🞆 Microsoft SQL Server 2012 is a database management system and as such offers a multitude of configuration settings
to control its behavior
🞆 Normalization is the process of organizing data in a database that includes establishing relationships between the tables
🞆 First normal form – no repeating groups
🞆 Second normal form – eliminate redundant data
🞆 Third normal form – eliminate data not dependent on the key
Summary
🞆 Disregarding the fourth and fifth normalization rules may not result in a perfect database design but shouldn’t affect
functionality.
🞆 Referential Integrity is used to ensure that data contained in the database remains consistent.
🞆 Tools that can be used to help with referential integrity include (Primary Key constraint, Foreign Key constraint,
Unique constraint, Unique Indexes and Triggers)
🞆 Primary key constraint – an attribute or set of attributes used to uniquely identify each row