Be Stronger Then You Excuses
Happiness is the best medicine.
Be Stronger Then You Excuses
Happiness is the best medicine.
Be Stronger Then You Excuses
Happiness is the best medicine.
Be Stronger Then You Excuses
Happiness is the best medicine.
Be Stronger Then You Excuses
Happiness is the best medicine.
SQL PRIMARY KEY
MS-SQL query and ShortcutKey
1:- Change Database Name using Query
Alter database Test modify name=Test1
you can also use system stored procedure
sp_renameDB 'Test1','Test'
2:- How to get all table name from database
First select database and run below query.
SELECT name FROM sys.tables
3:- How to Get All stored procedures in database.
SELECT ROUTINE_SCHEMA, ROUTINE_NAME
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_TYPE = 'PROCEDURE';
4:- Check Size of database
Run sp_spaceused Stored Procedure
exec sp_spaceused
2:- ShortCut Key
| Command Name | Shortcut Keys |
|---|---|
| Execute | F5 |
| Execute Current Statement | F8 |
| SQL Query History | CTRL+ALT+H |
| Edit Parameters | CTRL+SHIFT+P |
| Hide/Show additional document views | CTRL+R |
| Comment Selection | CTRL+K, C |
| UnComment Selection | CTRL+K, U |
| Go To Definition | F12 |
Transact-SQL Functions
Transact-SQL (T-SQL) functions are subprograms that encapsulate a sequence of T-SQL statements. T-SQL functions can return a single scalar value, a single row, or multiple rows.
There are two types
of T-SQL functions:
·
Scalar
functions: return a single scalar value, such as an integer, a string, or a
date/time value.
·
Table-valued
functions: return a table, allowing multiple rows to be returned and processed
like a physical table.
Some common T-SQL
functions include:
·
Aggregate
functions: COUNT, SUM, AVG, MIN, MAX, etc.
·
Date
and time functions: GETDATE, DATEADD, DATEDIFF, etc.
·
String
functions: LEN, SUBSTRING, CHARINDEX, etc.
·
Conversion
functions: CAST, CONVERT, etc.
System functions:
@@ROWCOUNT, @@IDENTITY, @@ERROR, etc.
Functions can be
used in T-SQL statements to manipulate data and simplify complex calculations.
Define all SQL COMPONENTS
SQL COMPONENTS
In This Chapter
SQL’s Basic Objects
• Data Types
• Transact-SQL Functions
• Scalar Operators
• NULL Values
The Transact-SQL language's foundational objects and
operations are introduced in this chapter.
First, descriptions are given of the fundamental language
components, such as constants, identifiers, and delimiters. Then, data types
are thoroughly covered because each elementary object has a corresponding data
type. All currently used operators and functions are also described. NULL
values are introduced at the chapter's conclusion.
SQL’s Basic Objects
Transact-SQL, the language of the Database Engine, shares
the following characteristics with other popular programming languages:
• Literal values (also called constants)
• Identifiers
• Delimiters
• Comments
• Reserved keywords
These features are described in the sections that follow.
Literal values
An alphanumeric, hexadecimal, or numerical constant is an
illustration of a literal value. One or more characters from the character set
are contained in single or double straight quote marks (' ') within a string
constant (" "). (Single quotation marks are recommended because
double quotation marks are frequently used, as will be covered in a moment.)
Use two consecutive single quotation marks to separate a string from another
string if you wish to include a single quotation mark in the string. In order
to represent nonprintable characters and other binary data, hexadecimal
constants are utilised. Every hexadecimal constant starts with the letters
"0x" and then an even number of letters or digits. Hexadecimal and other
valid and invalid string constants are shown in examples 4.1 and 4.2.
Example 4.1 Some valid string constants and hexadecimal
constants follow:
'Philadelphia'
"Berkeley, CA 94710"
'9876'
'Apostrophe is
displayed like this: can' 't' (note the two consecutive single quotation marks)
0x53514C0D
Example 4.2 The following are not string constants:
'AB'C' (odd number of single quotation marks) 'New
York" (same type of quotation mark—single or double—must be used at each
end of the string) The numeric constants include all integer, fixed-point, and
floating-point values with and without signs.
Identifiers: -
Identifiers are used in Transact-SQL to identify database
objects including databases, tables, and indices. They are represented as
character strings that can contain up to 128 characters, letters, numbers, or
the _, @, #, and $ characters. Each name must be preceded by a letter or one of
the symbols _, @, or #. A temporary object is indicated by the character # at
the start of a table or stored procedure name, whereas a variable is indicated by
the character @ at the start of a name. These guidelines don't apply to
delimited identifiers (also known as quoted identifiers), which can contain or
start with any character, as detailed in the following section (other than the
delimiters themselves).
Delimiters: -
Double quotation marks in Transact-SQL have two distinct
meanings. Double quotation marks can be used as a delimiter for so-called
delimited identifiers in addition to enclosing strings. A specific type of
identifier called a delimited identifier is typically used to permit the usage
of reserved words as identifiers and to permit spaces in the names of database
objects.
In Transact-SQL, the QUOTED IDENTIFIER option of the SET
statement is used to define the use of double quotation marks. An identifier
enclosed in double quotation marks will be regarded as a delimited identifier
if this option is turned on, which is the default setting. Double quote marks
cannot be used to separate strings in this situation.
Comments:-
In a Transact-SQL statement, there are two alternative ways to specify a comment. When the characters /* and */ are used, the surrounded content is designated as a comment. The comment in this instance might span multiple lines. Also indicating that the rest of the line is a comment are the characters — (two hyphens). (The two — are Transact-SQL additions, whereas /* and */ conform to the ANSI SQL standard.)
Data Types: -
A column's data values must all be of the same data type. (The SQL VARIANT data type's values are the sole exception.) Transact-SQL employs a variety of data types that fall into the following categories:
• Numeric data types
• Character data types
• Temporal (date and/or time) data types
• Miscellaneous data types
All these categories are described in the sections that follow.
Numeric Data Types:-
Character Data Types:-
In SQL, character data types are used to store character or
string values. The most commonly used character data types are:
CHAR(n): This data type is used to store fixed-length
character strings. The "n" in the parentheses specifies the maximum
number of characters that can be stored. For example, CHAR(10) can store a
maximum of 10 characters.
VARCHAR(n): This data type is used to store variable-length
character strings. The "n" in the parentheses specifies the maximum
number of characters that can be stored. For example, VARCHAR(50) can store a
maximum of 50 characters.
TEXT: This data type is used to store large text values that
may exceed the maximum limit of the CHAR or VARCHAR data types.
BLOB: This data type is used to store binary large objects
such as images, audio, or video files.
It's important to note that the maximum limit and storage
size may vary based on the database management system you are using.
FRONT-END TOOLS FOR THE DATABASE ENGINE
SQL Server Management Studio (SSMS) and Azure Data Studio
are two front-end tools for the Database Engine that are introduced in this
chapter. The two SSMS components, Registered Servers and Object Explorer, as
well as the numerous SSMS user interface panes, are first covered in this
chapter. The SSMS operations connected to the Database Engine are then covered.
Also discussed in relation to authoring activities in SSMS are the Query Editor
and Solution Explorer.
To assist DBAs and users who don't utilise Windows as the
platform for the Database Engine, Azure Data Studio has been created. You can
manage the instances of your database system and access data from pre-existing
databases using Azure Data Studio. There are fewer components available in this
component than in SSMS. At the conclusion of the chapter, a comparison of the
features of the two front-end tools is provided.
SQL Server Management Studio
For diverse tasks such system installation, configuration,
auditing, and performance tweaking, the Database Engine offers a variety of
tools. (This book's next chapters will explore each of these technologies.) SQL
Server Management Studio is the administrator's main tool for working with the
system on Windows systems. Among other things, SSMS can be used by both
administrators and end users to manage numerous servers, create databases, and
replicate data.
The SQL Server Management Studio installation process is
simple. Visit www.microsoft.com, click the magnifying glass symbol in the
top-right corner, type "SSMS" into the search bar, then press
"Enter." The Download SQL Server Management Studio (SSMS) link will
appear in the search results. Verify that your computer is running a supported
version of Windows on the page that appears, and then click the Download SQL
Server Management Studio link to access the most recent SSMS version (18.1 at
the time of writing). Once it has downloaded, run the associated.exe file,
click Install, and then wait for the installation to finish.
Simply click the matching icon to launch SQL Server Management
Studio, or click Start and enter Management Studio into Windows Desktop Search.
The total system is written, administered, and managed using a variety of
components that make up SQL Server Management Studio.
The following are the main components used for these tasks:
• Registered Servers
• Object Explorer
• Query Editor
• Solution Explorer
• Data Discovery and Classification
The first two components in the list are discussed in this
section. The latter three components are explained later in this chapter in
“Authoring Activities Using SQL Server Management Studio.”
To get to the main SQL Server Management Studio interface,
you first must connect to a server, as described next.
Connecting to a Server
The Connect to Server dialogue box, which is displayed when
SQL Server Management Studio is launched and allows you to enter the connection
information for a server, is displayed:
•
Server Type:- For purposes of this chapter, choose Database
Engine.
·
Server Name:- The server name you want to
use can be selected or typed. (In general, SQL Server Management Studio can be
linked to any installed products on a given server.)
·
Authentication:- Starting with SQL Server
Management Studio 17.2, the Connect to Server dialog box supports an extra
three authentication methods that are used to connect to Azure SQL Database and
Data Warehouse instances. The supported authentication methods are listed here:
·
Windows Authentication: - You connect to
the Database Engine using your Windows account. This option is recommended by
Microsoft.
·
SQL Server Authentication: - The Database
Engine uses its own authentication.
·
Active Directory – Universal with MFA support:
-This is an interactive authentication method that supports Azure Multi-Factor
Authentication, which provides strong authentication with a range of easy
verification options you can choose from.
·
Active Directory – Password and Active
Directory – Integrated:- These are non[1]interactive authentication methods supported by
Azure Active Directory Authentication and can be used in many applications such
as the ODBC and JDBC.
History Of SQL Server
One of the best database management systems
in the world is Microsoft SQL Server. It's widely utilised and continually
getting better. But do you understand how it was made?
I'll outline the development of MS SQL
Server, a product that revolutionised the database industry, in this essay. The
steps of MS SQL Server development will be discussed, along with how the
current version differs from the original and resources for learning or
practising SQL Server.
If you're starting (or continuing) your
journey with MS SQL Server, it's important to understand where it all began.
How Does MS SQL Server Work?
Relational
database management system (RDBMS) Microsoft SQL Server has a long history and
has undergone numerous modifications throughout the years. Since SQL Server
versions 1996 and 1999 are not regarded as full versions, the current version,
15.0, is actually the 17th.
Since
MS SQL was first released in 1989, it has taken 32 years for MS SQL Server to
evolve (and counting). Despite what you may believe, SQL Server is still one of
the most widely used and well maintained RDBMSs on the market.
You
don't need to be reminded that SQL Server is excellent software because it has
been used extensively for so long. The quantity of job vacancies that require
knowledge of MS SQL Server and the numbers speak for themselves. If database
management or any occupation involving data interests you, learning MS SQL is a
good idea. It can be challenging to work with data without MS SQL Server. It is
an established product with a developed market position. And the biggest businesses
in the world utilise it!
The
fact that SQL Server was created by Microsoft is one factor in its popularity.
Microsoft was already a major player in the technology world while MS SQL
Server was under development. It's not surprise that MS SQL Server became such
a well-liked method of data storage because it is a promising and significantly
more configurable tool. Even with a lot of data, handling it was simple and
effective.
Different editions of SQL Server are available today to meet various purposes (e.g. on cloud, on premises, for developers, or for small projects). A few of the editions are free. As befits an IT behemoth, Microsoft offers excellent customer care and can help you select the best edition for your requirements.
What Distinguishes SQL Server from Other DBMSs?
MS
SQL Server faces competition from other DMSs (DBMSs). The numerous tools and
programmes that make working with data easier are what set SQL Server apart.
Due to its comprehensive GUI (graphical user interface), working with the
database is simple and intuitive, and you can also generate statistics for
reports.
Because
SQL Server was designed, distributed, and produced by Microsoft, it has some of
the greatest customer service available. It offers very competent customer
service. You may rely on support for any difficult problems you encounter.
Another major benefit is the server's international user community, where you
can look for solutions to real-world issues.
T-SQL is the database's primary language of communication
while working with MS SQL Server (transactional SQL). This language differs
slightly from regular SQL in that it contains a few extra phrases and makes a
few minor grammar adjustments. If you are familiar with normal SQL, you won't
have any trouble learning T-SQL; for small variations, you can always consult
SQL Server's documentation.
The Evolution and History of MS SQL Server
The
introduction of MS SQL Server was meant to permanently alter database
administration solutions. Its growth was continuously encouraged. Microsoft was
a symbol of progress, reliability, and innovation at the time. All of this
contributed to SQL Server's extremely favourable reception.
When
Microsoft teamed up with Sybase and Ashton-Tate in 1988, MS SQL Server first
began to take shape. The objective was to create database management and
creation tools that would spark interest in Microsoft's commercial database
sector.
In
1989, SQL Server 1.0 was released. At that time, databases were created using
the System Administrator Facility (SAF). Users could perform SQL queries and
set parameters, but there was no documentation. Sybase wrote the original
Microsoft code.
In
1993, version 4.2 made its debut. The Windows graphical user interface was
first introduced in this version of MS SQL Server. Version 4.2 wasn't preceded
by 2.x or 3.x versions for unknown reasons, likely for the same reason that
Windows 7 came out after Windows Vista. The fact that SQL Server 4.2 supported
Windows NT and OS/2 marked a substantial improvement over its forerunner
(IBM-Microsoft OS). After splitting up later that year, Sybase and Microsoft
have independently pursued their own product and marketing ideas ever since. In
order to avoid any doubt regarding the manufacturer, Microsoft obtained
exclusive rights to all editions of SQL Server created for them.
In
1995, SQL Server 6.0, also referred to as SQL95, was made available. It was a
highly new and cutting-edge product that offered replication—a brand-new,
crucial feature.
The majority of the code for SQL Server 7.0 (1998) was rewritten for an earlier engine developed by Sybase, which Microsoft acquired from them in order to have complete control over the product. New tools like Query Analyzer, which could immediately provide thorough information about SQL Server's processor, were part of this release. The development of tables and indexes, replication, backup scheduling, etc. was simple and entertaining thanks to a new graphical user interface and administrative wizards. Since Microsoft first entered the corporate database market, this version of SQL Server has been the most significant.
It was designed to be more adaptable, significantly more effective,
and simpler to operate. SQL OLAP Services were also introduced by SQL Server
7.0. (which became Analysis Services in the next version).
Even
additional updates to the code base and adjustments were added to SQL Server
2000 version 8.0. This version boasted enhanced efficiency and added T-SQL
additions for increased functionality, such as table variables, indexed views,
triggers, or user-defined functions. This version also added support for XML
and HTTP, performance and accessibility improvements for loading partitions,
and enhanced administration options for automating database tasks.
Along with relational data processing, SQL Server
2005 9.0 ("Yukon") introduced native support for XML data management.
Additionally, it allowed for TDS-based provisioning of the database server over
the Internet (Tabular Data Stream). When compared to the original MS SQL Server
version, this edition's security was much strengthened; it can be regarded as
ultra-technological.
Backup compression and change data capture, two new features of SQL Server 2008 10.0, were included (CDC). It permitted the storage of a variety of data kinds, including documents, XML files, calendars, and email. Working with data is now lot simpler and more logical because to Microsoft's continued software performance improvements and database administration simplification.
Basic SQL question and answer quiz
SQL database interview question for fresher
1.What is SQL?
SQL stands for structured query language and we can access and manipulate databases.
2.How to create a table in SQL?
Connecting to SQL Server using SSMS,Install Sql server 2019 Step by Step
Introduction
In this post, we'll go over step-by-step instructions for installing Microsoft SQL Server on Windows computers. We'll use Windows Server 2019 and SQL Server 2019 Developer edition for this tutorial.
Pre-requisites
Using a Windows computer with a 2 core and 4 GB of RAM
Download the 2019 Developer Edition of SQL Server.
Download the SQL Server installation files from the official website
first.
Let start with how to install SQL Server.
1. Download Microsoft SQL Server from the below url.
https://www.microsoft.com/en-au/sql-server/sql-server-downloads
2. After download click sqlexpress.exe.
Click on the Installation page and then on ‘New SQL Server stand-alone installation or add features to an existing installation’
Select Evaluation and click the Next Button.
Note
Standard Instance
A client does not need to give the name of the instance when connecting to SQL Server when it is installed in the default instance. Only the server name needs to be known by the client. HARDIK-PC, as an illustration.
Known instance
The network name of the computer and the instance you choose during
installation together identify a named instance. When connecting, the client
must include both the server name and the instance name. HARDIK-PC/MSSQLSERVER,
as an illustration.
"SQL Server's correlations include sorting criteria, case and accent
sensitivity, and other properties for your data. The code page and related
characters that can be represented for character data types like char and
varchar are determined by collations used with those data types. – Microsoft”
Specify Authentication modes (Windows or Mixed mode) and add users to have SQL Server administrators.
The Database Engine
Configuration window will appear after that. Select Mixed Mode under
Authentication Mode in the Server Configuration tab, and then enter a strong
password. Your current Windows user should already be automatically inserted in
the "Specify SQL Server administrators" section. Alternatively,
select the Add Current User option.
Click on Data Directories and we can specify the data, log files, backup directories here.
Place database files and backup files in the locations you choose in the Data Directories tab. By default, it saves all of the files to the C drive, however it is not advisable to store database files on an OS drive because we risk losing our data if an OS-related problem arises. I therefore select my local machine's D drive.
Click on TempDB to configure the TempDB configurations. We will move with the default configuration suggested by the installer.
There are
configurations for the temporary database file in the TempDB tab (s). There are
certain recommended configuration settings for the locations, number, and size
of temporary database files. The number of logical processors should ideally
match the number of TempDB data files. I therefore have a lot of files to 2.
Here is a fantastic post on TempDB best practises if you're interested in
learning more.
We won't be using
this feature, therefore keep the checkbox unchecked under the FILESTREAM tab.
These huge files, photos, or documents can be stored directly on the file
system using SQL Server's FILESTREAM feature. For additional details, click on
Next button.
We get an overview of the SQL Server configurations from the Ready to install page. Review the information and click on next to start the installation process.
Once the installation is completed, launch SSMS 18.0 preview to connect with SQL Server.
Congratulations!
We have successfully installed SQL Server 2019 Developer edition on Windows
machine. Next, you can install SQL Server Management Studio to connect SQL
Server and query SQL databases. Please follow below steps to install SQL Server
Management Studio.
SSMS:-
SQL Server Management Studio is a client tool not the server by itself.
Creating altering and dropping a database
Creating database From GUI:-
Creating and working with table
Adding A default constraints
A column default can be specified using default constraints. The default constraint is used to insert a default value into a column. The default value will be added to all new record, if no other values is specified, including null.

Altering an existing column to add a default constraint
Syntax:-
Alter table table_name add constraint (constraints_name) default (default_value) for (existing column name)
Query:-
Alter table tblemployee add constraint df_tblgender_gnderid default 3 for genderId
NOTE
Tblemployee = table name
Df_tblgender_gnderid = default constraint
3= Default value
Cascading referential integrity constraint
Adding a check Constraint
Check Constraint:- Check Constraint is used to limit the range of the values, Which can be entered into a column.
The general formula for check constraint in sql server
Alter tabla (tablname) add constraint (constraint name) check (Boolean expression )
Identity Column in SQL Server
What is an Identity Column?
Create an Identity column
Unique key constraint
We use the UNIQUE constraint to enforce the uniqueness of a column i.e. the column should not allow any duplicate values. We can add a unique constraint through the designer or using a query.
To add a unique constraint using MS SQL Server Management Studio Designer:
1. Right click on the table and select Design option.
2. Right click on the column and select Indexes/Keys option..
3. Click Add option
4. For Columns, select the column name you want to be unique.
5. For Type, choose Unique Key.
6. Click Close, Save the table.
To create the unique key using a query:
Alter Table Table_Name
Add Constraint Constraint_Name Unique(Column_Name)
Used to implement both primary keys and unique keys, a column's uniqueness. So, when do you choose each other? A table can have only one primary key. If you want to apply exclusivity to 2 or more columns, we use the unique key constraint
What is the difference between a primary key constraint and a specific key constraint? This question is mostly asked in interviews.
1. One table can have only one primary key, but more than one unique key.
2. The primary key does not allow taps, where the unique key allows a tap
Hitch up
1. Right click on the constraint and delete.
or
2. Using a Query
Alter table tblPerson
Drop Constant UQ_tblPerson_Email
Select statement in MS sql server
SELECT Column_List
FROM Table_Name
If you want to select all the data(column), you can also use (* ) For better performance use the column list, instead of using (*.)
SELECT * FROM Table_Name
To Select distinct rows use DISTINCT keyword
SELECT DISTINCT Column_List FROM Table_Name
Example: Select distinct city from tblPerson
Filtering rows with WHERE clause
SELECT Column_List FROM Table_Name WHERE Filter_Condition
Example: Select Name, Email from tblemployee where City = 'London'
Note: Text values must exist in single quotes, but are not required for numeric values.































