SlideShare una empresa de Scribd logo
1 de 46
Introduction To MS SQL
Server
Introduction
• MS SQL Server is a database server
• Product of Microsoft
• Enables user to write queries and other SQL statements and execute them
• Consists of several features. A few are:
– Query Analyzer
– Profiler
– Service Manager
– Bulk Copy Program (BCP)
Profiler
• Monitoring tool
• Used for performance tuning
• Uses traces – an event monitoring protocol
• Event may be a query or a transaction like logins etc
Service Manager
• Helps us to manage services
• More than one instance of SQL server can be installed in a machine
• First Instance is called as default instance
• Rest of the instances (16 max) are called as named instances
• Service manager helps in starting or stopping the instances individually
Instances
• Each instance is hidden from another instance
• Enhances security
• Every instance has its own set of Users, Admins, Databases, Collations
• Advantage of having multiple instance is
– Multi company support (Each company can have its own instance and
create databases on the same server, independent on each other)
– Server consolidation (Can host up to 10 server applications on a single
machine)
BCP
• Bulk Copy Program
• A powerful command line utility that enables us to transfer large number
of records from a file to database
• Time taken for copying to and from database is very less
• Helps in back up and restoration
Query Analyzer
• Allows us to write queries and SQL statements
• Checks syntax of the SQL statement written
• Executes the statements
• Store and reload statements
• Save the results in file
• View reports (either as grid or as a text)
SQL Database Objects
• A SQL Server database has lot of objects like
– Tables
– Views
– Stored Procedures
– Functions
– Rules
– Defaults
– Cursors
– Triggers
System Databases
• By default SQL server has 4 databases
– Master : System defined stored procedures, login details,
configuration settings etc
– Model : Template for creating a database
– Tempdb : Stores temporary tables. This db is created when the server
starts and dropped when the server shuts down
– Msdb : Has tables that have details with respect to alerts, jobs. Deals
with SQL Server Agent Service
Creating a database
• We need to use Master database for creating a database
• By default the size of a database is 1 MB
• A database consists of
– Master Data File (.mdf)
– Primary Log File (.ldf)
Database operations
• Changing a database
Use <dbname>
• Creating a database
Create database <dbname>
• Dropping a database
Drop database <dbname>
SQL Server Data types
• Integer : Stores whole number
• Float : Stores real numbers
• Text : Stores characters
• Decimal: Stores real numbers
• Money : Stores monetary data. Supports 4 places after decimal
• Date : Stores date and time
• Binary : Stores images and other large objects
• Miscellaneous : Different types special to SQL Server.
(Refer to notes for more info)
Operators
• Arithmetic
• Assignment
• Comparison
• Logical
• String
• Unary
• Bitwise
Select Statements
• To execute a statement in MS SQL, Select the statement and Click on the Execute
button in the query analyser or press F5
• This is used to retrive records from a table
• Eg. Select * from table1;
– This will fetch all rows and all columns from table1
• Eg. Select col1,col2 from table1
– This will fetch col1 and col2 from table1 for all rows
• Eg. Select * from table1 where <<condn>>
– This will fetch all rows from table1 that satisfies a condition
• Eg. Select col1,col2 from table1 where <<condn>>
– This will fetch col1 and col2 of rows from table1 that satisfies a condition
Select Options
• Aggregate functions
– Sum(col1): sum of data in the column col1
– Max(col1): data with maximum value in col1
– Min(col1): data with minimum value in col1
– Avg(col1): Average of data in col1
– Count(col1): Number of not null records in table
• Grouping – Group by col1 : Groups data by col1
• Ordering – Order by col1 : Orders the result in ascending order (default
order) of col1
• Filtering – Where <<condn>> and Having <<condn>>
Table management
Create table tablename
(
col1 data type,
col2 data type
);
- Creates a table with two columns
Drop table tablename;
- Drops the table structure
Insert statements
• Inserting data to all columns
– Insert into tablename(col1,col2) values(v1,v2)
– Insert into tablename values(v1,v2)
• Inserting data to selected columns
– Insert into tablename(col1) values (v1)
– Insert into tablename(col2) values (v2)
Update statement
Update table tablename
Set colname=value
- This updates all rows with colname set to value
Update table tablename
Set colname=value
Where <<condition>>
- This updates selected rows with colname as value only if the row
satisfies the condition
Delete statements
Delete from table1;
Deletes all rows in table1
Delete from table1 where <<condition>>
Deletes few rows from table1 if they satisfy the condition
Truncate statement
• Truncate table tablename
• Removes all rows in a table
• Resets the table.
• Truncate does the following, where as delete statement does not
– Releases the memory used
– Resets the identity value
– Does not invoke delete trigger
Alter statements
• Used to modify table structure
– Add new column
– Change data type of existing column
– Delete a column
– Add or remove constraints like foreign key, primary key
More table commands
• Viewing tables in a data base:
– Exec sp_tables “a%”
– This gives all tables in the current database that starts with “a”
• Viewing table strucure:
– Exec sp_columns <<tablename>>
– Exec sp_columns student;
Joins
• Cross Join
– Cartesian product. Simply merges two tables.
• Inner Join
– Cross join with a condition. Used to find matching records in the two
tables
• Outer Join
– Used to find un matched rows in the two tables
• Self Join
– Joining a table with itself
Cross Join
There are two tables A and B
A has a column Id and data (1,2,3)
B has a column Id and data (A,B)
If I put
Select A.Id, B.Id from A,B
This generates output as
A 1
B 1
C 1
A 2
B 2
C 2
Self Join
There is a table called Emp with the following structure:
empid ename mgrid
1 A null
2 B 1
3 C 1
4 D 2
If I want to print all managers using self join, I should write quey as:
select e1.ename from
emp e1,emp e2
where e1.mgrid = e2.empid
Inner Join
I have 2 tables Student(sid,Name) and Marks(Sid,Subject,Score)
If I want to print the marks of all students in the following format,
Name Subject Score
Select Name,Subject,Score from
Student s join Marks m
On s.sid = m.sid
Outer Join
• Right outer Join
– Print all the records in the second table with null values for missing
records in the first table
• Left outer Join
– Print all the records in the first table with null values for missing
records in the second table
• Full outer Join
– Prints all records in both the table with null values for missing records
in both the table
Left Outer Join
I have a table Employee (Eid, Ename, Mid) and
a table Machine (Mid,ManufacturerName)
Employee
Eid EName Mid
1 ABC 1
2 DEF 3
Machine
Mid ManufacturerName
1 Zenith
2 HP
Left Outer Join
I want to print the employee name and machine name.
If I write a query using inner join, then the second employee will
not be displayed as the mid in his record is not avilable with the second
table.
So I go for left outer join. The query is as shown below:
Select Ename, ManufacturerName from Employee e left outer join
Machine m on e.Mid = m.Mid
Right outer Join
Assume data in the tables like this:
Employee
Eid EName Mid
1 ABC 1
2 DEF
Machine
Mid ManufacturerName
1 Zenith
2 HP
Right Outer Join
If I want to find which machine is unallocated, I can use right outer join.
The query is as follows:
Select Ename, ManufacturerName from Employee e right outer join
Machine m on e.Mid = m.Mid
This yields a result
ABC Zenith
HP
Full Outer Join
Assume data in the tables like this:
Employee
Eid EName Mid
1 ABC 1
2 DEF
3 GHI 2
Machine
Mid ManufacturerName
1 Zenith
2 HP
3 Compaq
Full Outer Join
If I want to find people who have been un allocated with a system and
machines that are been un allocated, I can go for full outer join.
Query is like this:
Select Ename, ManufacturerName from Employee e full outer join
Machine m on e.Mid = m.Mid
This yields a result
ABC Zenith
DEF
GHI HP
Compaq
Views
• Views are logical tables
• They are pre compiled objects
• We can select few columns or rows from a table and put the data set in a
view and can use view in the same way as we use tables
Views
• Create views:
Create view viewname as select stmt
Create view view_emp as select empid,
empname from employee;
• Select from views:
Select * from viewname
Select empid,empname view_emp;
• Drop views:
Drop view viewname
Drop view view_emp;
String Functions
• Substring(string,start,length) – Will fetch characters starting at a specific
index extending to length specified.
• Left(string,length) – Fetches number of characters specified by length
from left of the string
• Right(string,length) – Fetches number of characters specified by length
from right of the string
• Len(string) – Returns the length of a string
String Functions
• Ltrim(string) – Removes leading spaces in a string
• Rtrim(string) – Removes trailing spaces in a string
• Lower(string) – Converts the characters in a string to lower case
• Upper(string) – Converts the characters in a string to upper case
Numeric Functions
• ABS(Number) – Fetches the modulo value (Positive value) of a number
• CEILING(Number) – Fetches the closest integer greater than the number
• FLOOR(Number) – Fetches the closest integer smaller than the number
• EXP(Number) – Fetches the exponent of a number
Numeric Functions
• POWER(x,y) – Fetches x raised to the power of y
• LOG(Number) – Fetches the natural logarithmic value of the number
• LOG10(Number) – Fetches log to the base 10 of a number
• SQRT(Number) – Fetches the square root of a number
Indexes
• Indexes make search and retrieve fast in a database
• This is for optimizing the select statement
• Types of index
– Unique
– Non unique
– Clustered
– Non clustered
Index
Create index indexname on
tablename(columnname)
This creates a non clustered index on a table
Create unique clustered index index_name on
Student(sname);
This creates a unique and clustered index on the
Column Sname.
Sequences
• This creates an auto increment for a column
• If a table has a column with sequence or auto increment, the user need
not insert data explicitly for the column
• Sequence is implemented using the concept of Identity
Identity
• Identity has
– A seed
– An increment
• Seed is the initial value
• Increment is the value by which we need to skip to fetch the nextvalue
• Identity(1,2) will generate sequence numbers 1,3,5,7…
Sample
Create table table1
(
Id integer identity(1,1),
Name varchar(10)
)
It is enough if we insert like this:
Insert into table1(name) values(‘Ram’);
Ram will automatically assigned value 1 for id
Thank You !!!
For More Information click below link:
Follow Us on:
http://vibranttechnologies.co.in/sql-server-classes-in-mumbai.html

Más contenido relacionado

La actualidad más candente

Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Faisal Anwar
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsZohar Elkayam
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniqueskumar gaurav
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsOOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Import Data using R
Import Data using R Import Data using R
Import Data using R Rupak Roy
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
XML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSimXML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSimWai Nwe Tun
 
R - Get Started I - Sanaitics
R - Get Started I - SanaiticsR - Get Started I - Sanaitics
R - Get Started I - SanaiticsVijith Nair
 
How mysql choose the execution plan
How mysql choose the execution planHow mysql choose the execution plan
How mysql choose the execution plan辛鹤 李
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
 
Import and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R StudioImport and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R StudioRupak Roy
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Import and Export Excel files using XLConnect in R Studio
Import and Export Excel files using XLConnect in R StudioImport and Export Excel files using XLConnect in R Studio
Import and Export Excel files using XLConnect in R StudioRupak Roy
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 

La actualidad más candente (20)

Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
MySQL index optimization techniques
MySQL index optimization techniquesMySQL index optimization techniques
MySQL index optimization techniques
 
Etl2
Etl2Etl2
Etl2
 
Sap abap
Sap abapSap abap
Sap abap
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsOOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
 
Import Data using R
Import Data using R Import Data using R
Import Data using R
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
XML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSimXML introduction and Uses of XML in JSBSim
XML introduction and Uses of XML in JSBSim
 
R - Get Started I - Sanaitics
R - Get Started I - SanaiticsR - Get Started I - Sanaitics
R - Get Started I - Sanaitics
 
Vertica
VerticaVertica
Vertica
 
How mysql choose the execution plan
How mysql choose the execution planHow mysql choose the execution plan
How mysql choose the execution plan
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
 
Import and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R StudioImport and Export Excel Data using openxlsx in R Studio
Import and Export Excel Data using openxlsx in R Studio
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
Import and Export Excel files using XLConnect in R Studio
Import and Export Excel files using XLConnect in R StudioImport and Export Excel files using XLConnect in R Studio
Import and Export Excel files using XLConnect in R Studio
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 

Destacado

Hadoop - An introduction for SQL Server DBAs
Hadoop - An introduction for SQL Server DBAsHadoop - An introduction for SQL Server DBAs
Hadoop - An introduction for SQL Server DBAsandrewdenty
 
Introduction To SQL Server 2014
Introduction To SQL Server 2014Introduction To SQL Server 2014
Introduction To SQL Server 2014Vishal Pawar
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introductionRiteshkiit
 
Introduction to microsoft sql server 2008 r2
Introduction to microsoft sql server 2008 r2Introduction to microsoft sql server 2008 r2
Introduction to microsoft sql server 2008 r2Eduardo Castro
 
Microsoft sql server architecture
Microsoft sql server architectureMicrosoft sql server architecture
Microsoft sql server architectureNaveen Boda
 
Microsoft SQL Server internals & architecture
Microsoft SQL Server internals & architectureMicrosoft SQL Server internals & architecture
Microsoft SQL Server internals & architectureKevin Kline
 
MS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database ConceptsMS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database ConceptsDataminingTools Inc
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 

Destacado (15)

Hadoop - An introduction for SQL Server DBAs
Hadoop - An introduction for SQL Server DBAsHadoop - An introduction for SQL Server DBAs
Hadoop - An introduction for SQL Server DBAs
 
Intro to sql
Intro to sqlIntro to sql
Intro to sql
 
Introduction To SQL Server 2014
Introduction To SQL Server 2014Introduction To SQL Server 2014
Introduction To SQL Server 2014
 
Sql server introduction
Sql server introductionSql server introduction
Sql server introduction
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Introduction to microsoft sql server 2008 r2
Introduction to microsoft sql server 2008 r2Introduction to microsoft sql server 2008 r2
Introduction to microsoft sql server 2008 r2
 
Microsoft sql server architecture
Microsoft sql server architectureMicrosoft sql server architecture
Microsoft sql server architecture
 
Microsoft SQL Server internals & architecture
Microsoft SQL Server internals & architectureMicrosoft SQL Server internals & architecture
Microsoft SQL Server internals & architecture
 
MS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTUREMS-SQL SERVER ARCHITECTURE
MS-SQL SERVER ARCHITECTURE
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
SQL : introduction
SQL : introductionSQL : introduction
SQL : introduction
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
MS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database ConceptsMS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database Concepts
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 

Similar a Sql server introduction to sql server

OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptxRajendra Jain
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentationMichael Keane
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 
Oracle Course
Oracle CourseOracle Course
Oracle Courserspaike
 
Sap abap
Sap abapSap abap
Sap abapnrj10
 
Java class 8
Java class 8Java class 8
Java class 8Edureka!
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationVolodymyr Rovetskiy
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slidesmetsarin
 
ds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptAlliVinay1
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sSveta Smirnova
 
Python SQLite3...
Python                                                                SQLite3...Python                                                                SQLite3...
Python SQLite3...VikasTuwar1
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Web Services
 

Similar a Sql server introduction to sql server (20)

OracleSQLraining.pptx
OracleSQLraining.pptxOracleSQLraining.pptx
OracleSQLraining.pptx
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Dbms &amp; oracle
Dbms &amp; oracleDbms &amp; oracle
Dbms &amp; oracle
 
In memory databases presentation
In memory databases presentationIn memory databases presentation
In memory databases presentation
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Oracle Course
Oracle CourseOracle Course
Oracle Course
 
presentation Updated.pdf
presentation Updated.pdfpresentation Updated.pdf
presentation Updated.pdf
 
Sap abap
Sap abapSap abap
Sap abap
 
Java class 8
Java class 8Java class 8
Java class 8
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentation
 
Data structure
Data structureData structure
Data structure
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
ds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.ppt
 
SQL LECTURE.pptx
SQL LECTURE.pptxSQL LECTURE.pptx
SQL LECTURE.pptx
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
Python SQLite3...
Python                                                                SQLite3...Python                                                                SQLite3...
Python SQLite3...
 
Amazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and OptimizationAmazon Redshift: Performance Tuning and Optimization
Amazon Redshift: Performance Tuning and Optimization
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 

Más de Vibrant Technologies & Computers

Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Vibrant Technologies & Computers
 

Más de Vibrant Technologies & Computers (20)

Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5Buisness analyst business analysis overview ppt 5
Buisness analyst business analysis overview ppt 5
 
SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables  SQL Introduction to displaying data from multiple tables
SQL Introduction to displaying data from multiple tables
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
SQL- Introduction to SQL database
SQL- Introduction to SQL database SQL- Introduction to SQL database
SQL- Introduction to SQL database
 
ITIL - introduction to ITIL
ITIL - introduction to ITILITIL - introduction to ITIL
ITIL - introduction to ITIL
 
Salesforce - Introduction to Security & Access
Salesforce -  Introduction to Security & Access Salesforce -  Introduction to Security & Access
Salesforce - Introduction to Security & Access
 
Data ware housing- Introduction to olap .
Data ware housing- Introduction to  olap .Data ware housing- Introduction to  olap .
Data ware housing- Introduction to olap .
 
Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.Data ware housing - Introduction to data ware housing process.
Data ware housing - Introduction to data ware housing process.
 
Data ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housingData ware housing- Introduction to data ware housing
Data ware housing- Introduction to data ware housing
 
Salesforce - classification of cloud computing
Salesforce - classification of cloud computingSalesforce - classification of cloud computing
Salesforce - classification of cloud computing
 
Salesforce - cloud computing fundamental
Salesforce - cloud computing fundamentalSalesforce - cloud computing fundamental
Salesforce - cloud computing fundamental
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
SQL- Introduction to advanced sql concepts
SQL- Introduction to  advanced sql conceptsSQL- Introduction to  advanced sql concepts
SQL- Introduction to advanced sql concepts
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 
SQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set OperationsSQL- Introduction to SQL Set Operations
SQL- Introduction to SQL Set Operations
 
Sas - Introduction to designing the data mart
Sas - Introduction to designing the data martSas - Introduction to designing the data mart
Sas - Introduction to designing the data mart
 
Sas - Introduction to working under change management
Sas - Introduction to working under change managementSas - Introduction to working under change management
Sas - Introduction to working under change management
 
SAS - overview of SAS
SAS - overview of SASSAS - overview of SAS
SAS - overview of SAS
 
Teradata - Architecture of Teradata
Teradata - Architecture of TeradataTeradata - Architecture of Teradata
Teradata - Architecture of Teradata
 
Teradata - Restoring Data
Teradata - Restoring Data Teradata - Restoring Data
Teradata - Restoring Data
 

Último

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

Sql server introduction to sql server

  • 1.
  • 2. Introduction To MS SQL Server
  • 3. Introduction • MS SQL Server is a database server • Product of Microsoft • Enables user to write queries and other SQL statements and execute them • Consists of several features. A few are: – Query Analyzer – Profiler – Service Manager – Bulk Copy Program (BCP)
  • 4. Profiler • Monitoring tool • Used for performance tuning • Uses traces – an event monitoring protocol • Event may be a query or a transaction like logins etc
  • 5. Service Manager • Helps us to manage services • More than one instance of SQL server can be installed in a machine • First Instance is called as default instance • Rest of the instances (16 max) are called as named instances • Service manager helps in starting or stopping the instances individually
  • 6. Instances • Each instance is hidden from another instance • Enhances security • Every instance has its own set of Users, Admins, Databases, Collations • Advantage of having multiple instance is – Multi company support (Each company can have its own instance and create databases on the same server, independent on each other) – Server consolidation (Can host up to 10 server applications on a single machine)
  • 7. BCP • Bulk Copy Program • A powerful command line utility that enables us to transfer large number of records from a file to database • Time taken for copying to and from database is very less • Helps in back up and restoration
  • 8. Query Analyzer • Allows us to write queries and SQL statements • Checks syntax of the SQL statement written • Executes the statements • Store and reload statements • Save the results in file • View reports (either as grid or as a text)
  • 9. SQL Database Objects • A SQL Server database has lot of objects like – Tables – Views – Stored Procedures – Functions – Rules – Defaults – Cursors – Triggers
  • 10. System Databases • By default SQL server has 4 databases – Master : System defined stored procedures, login details, configuration settings etc – Model : Template for creating a database – Tempdb : Stores temporary tables. This db is created when the server starts and dropped when the server shuts down – Msdb : Has tables that have details with respect to alerts, jobs. Deals with SQL Server Agent Service
  • 11. Creating a database • We need to use Master database for creating a database • By default the size of a database is 1 MB • A database consists of – Master Data File (.mdf) – Primary Log File (.ldf)
  • 12. Database operations • Changing a database Use <dbname> • Creating a database Create database <dbname> • Dropping a database Drop database <dbname>
  • 13. SQL Server Data types • Integer : Stores whole number • Float : Stores real numbers • Text : Stores characters • Decimal: Stores real numbers • Money : Stores monetary data. Supports 4 places after decimal • Date : Stores date and time • Binary : Stores images and other large objects • Miscellaneous : Different types special to SQL Server. (Refer to notes for more info)
  • 14. Operators • Arithmetic • Assignment • Comparison • Logical • String • Unary • Bitwise
  • 15. Select Statements • To execute a statement in MS SQL, Select the statement and Click on the Execute button in the query analyser or press F5 • This is used to retrive records from a table • Eg. Select * from table1; – This will fetch all rows and all columns from table1 • Eg. Select col1,col2 from table1 – This will fetch col1 and col2 from table1 for all rows • Eg. Select * from table1 where <<condn>> – This will fetch all rows from table1 that satisfies a condition • Eg. Select col1,col2 from table1 where <<condn>> – This will fetch col1 and col2 of rows from table1 that satisfies a condition
  • 16. Select Options • Aggregate functions – Sum(col1): sum of data in the column col1 – Max(col1): data with maximum value in col1 – Min(col1): data with minimum value in col1 – Avg(col1): Average of data in col1 – Count(col1): Number of not null records in table • Grouping – Group by col1 : Groups data by col1 • Ordering – Order by col1 : Orders the result in ascending order (default order) of col1 • Filtering – Where <<condn>> and Having <<condn>>
  • 17. Table management Create table tablename ( col1 data type, col2 data type ); - Creates a table with two columns Drop table tablename; - Drops the table structure
  • 18. Insert statements • Inserting data to all columns – Insert into tablename(col1,col2) values(v1,v2) – Insert into tablename values(v1,v2) • Inserting data to selected columns – Insert into tablename(col1) values (v1) – Insert into tablename(col2) values (v2)
  • 19. Update statement Update table tablename Set colname=value - This updates all rows with colname set to value Update table tablename Set colname=value Where <<condition>> - This updates selected rows with colname as value only if the row satisfies the condition
  • 20. Delete statements Delete from table1; Deletes all rows in table1 Delete from table1 where <<condition>> Deletes few rows from table1 if they satisfy the condition
  • 21. Truncate statement • Truncate table tablename • Removes all rows in a table • Resets the table. • Truncate does the following, where as delete statement does not – Releases the memory used – Resets the identity value – Does not invoke delete trigger
  • 22. Alter statements • Used to modify table structure – Add new column – Change data type of existing column – Delete a column – Add or remove constraints like foreign key, primary key
  • 23. More table commands • Viewing tables in a data base: – Exec sp_tables “a%” – This gives all tables in the current database that starts with “a” • Viewing table strucure: – Exec sp_columns <<tablename>> – Exec sp_columns student;
  • 24. Joins • Cross Join – Cartesian product. Simply merges two tables. • Inner Join – Cross join with a condition. Used to find matching records in the two tables • Outer Join – Used to find un matched rows in the two tables • Self Join – Joining a table with itself
  • 25. Cross Join There are two tables A and B A has a column Id and data (1,2,3) B has a column Id and data (A,B) If I put Select A.Id, B.Id from A,B This generates output as A 1 B 1 C 1 A 2 B 2 C 2
  • 26. Self Join There is a table called Emp with the following structure: empid ename mgrid 1 A null 2 B 1 3 C 1 4 D 2 If I want to print all managers using self join, I should write quey as: select e1.ename from emp e1,emp e2 where e1.mgrid = e2.empid
  • 27. Inner Join I have 2 tables Student(sid,Name) and Marks(Sid,Subject,Score) If I want to print the marks of all students in the following format, Name Subject Score Select Name,Subject,Score from Student s join Marks m On s.sid = m.sid
  • 28. Outer Join • Right outer Join – Print all the records in the second table with null values for missing records in the first table • Left outer Join – Print all the records in the first table with null values for missing records in the second table • Full outer Join – Prints all records in both the table with null values for missing records in both the table
  • 29. Left Outer Join I have a table Employee (Eid, Ename, Mid) and a table Machine (Mid,ManufacturerName) Employee Eid EName Mid 1 ABC 1 2 DEF 3 Machine Mid ManufacturerName 1 Zenith 2 HP
  • 30. Left Outer Join I want to print the employee name and machine name. If I write a query using inner join, then the second employee will not be displayed as the mid in his record is not avilable with the second table. So I go for left outer join. The query is as shown below: Select Ename, ManufacturerName from Employee e left outer join Machine m on e.Mid = m.Mid
  • 31. Right outer Join Assume data in the tables like this: Employee Eid EName Mid 1 ABC 1 2 DEF Machine Mid ManufacturerName 1 Zenith 2 HP
  • 32. Right Outer Join If I want to find which machine is unallocated, I can use right outer join. The query is as follows: Select Ename, ManufacturerName from Employee e right outer join Machine m on e.Mid = m.Mid This yields a result ABC Zenith HP
  • 33. Full Outer Join Assume data in the tables like this: Employee Eid EName Mid 1 ABC 1 2 DEF 3 GHI 2 Machine Mid ManufacturerName 1 Zenith 2 HP 3 Compaq
  • 34. Full Outer Join If I want to find people who have been un allocated with a system and machines that are been un allocated, I can go for full outer join. Query is like this: Select Ename, ManufacturerName from Employee e full outer join Machine m on e.Mid = m.Mid This yields a result ABC Zenith DEF GHI HP Compaq
  • 35. Views • Views are logical tables • They are pre compiled objects • We can select few columns or rows from a table and put the data set in a view and can use view in the same way as we use tables
  • 36. Views • Create views: Create view viewname as select stmt Create view view_emp as select empid, empname from employee; • Select from views: Select * from viewname Select empid,empname view_emp; • Drop views: Drop view viewname Drop view view_emp;
  • 37. String Functions • Substring(string,start,length) – Will fetch characters starting at a specific index extending to length specified. • Left(string,length) – Fetches number of characters specified by length from left of the string • Right(string,length) – Fetches number of characters specified by length from right of the string • Len(string) – Returns the length of a string
  • 38. String Functions • Ltrim(string) – Removes leading spaces in a string • Rtrim(string) – Removes trailing spaces in a string • Lower(string) – Converts the characters in a string to lower case • Upper(string) – Converts the characters in a string to upper case
  • 39. Numeric Functions • ABS(Number) – Fetches the modulo value (Positive value) of a number • CEILING(Number) – Fetches the closest integer greater than the number • FLOOR(Number) – Fetches the closest integer smaller than the number • EXP(Number) – Fetches the exponent of a number
  • 40. Numeric Functions • POWER(x,y) – Fetches x raised to the power of y • LOG(Number) – Fetches the natural logarithmic value of the number • LOG10(Number) – Fetches log to the base 10 of a number • SQRT(Number) – Fetches the square root of a number
  • 41. Indexes • Indexes make search and retrieve fast in a database • This is for optimizing the select statement • Types of index – Unique – Non unique – Clustered – Non clustered
  • 42. Index Create index indexname on tablename(columnname) This creates a non clustered index on a table Create unique clustered index index_name on Student(sname); This creates a unique and clustered index on the Column Sname.
  • 43. Sequences • This creates an auto increment for a column • If a table has a column with sequence or auto increment, the user need not insert data explicitly for the column • Sequence is implemented using the concept of Identity
  • 44. Identity • Identity has – A seed – An increment • Seed is the initial value • Increment is the value by which we need to skip to fetch the nextvalue • Identity(1,2) will generate sequence numbers 1,3,5,7…
  • 45. Sample Create table table1 ( Id integer identity(1,1), Name varchar(10) ) It is enough if we insert like this: Insert into table1(name) values(‘Ram’); Ram will automatically assigned value 1 for id
  • 46. Thank You !!! For More Information click below link: Follow Us on: http://vibranttechnologies.co.in/sql-server-classes-in-mumbai.html

Notas del editor

  1. Use master; Create database dbtest On primary ( name = softsmith, filename = ‘c:\test\softsmith.mdf’, size = 10 MB, maxsize = 20, filegrowth = 2 ) Log on ( name = softsmithlog, filename = ‘c:\test\softsmith.ldf’, size = 10 MB, maxsize = 20, filegrowth = 2 ) This creates a database with the name softsmith. The datafile softsmith.mdf and log file softsmith.ldf will be created in the path c:\test. The size of database is 10 MB.
  2. Integer: Bit- 1 bit Tinyint- 1 byte Smallint- 2 bytes Int- 4 bytes Bigint- 8 bytes Float: Float Real Text: Non unicode string: A character occupies 1 byte Char Varchar Text Unicode string: A character occupies 2 bytes Nchar Nvarchar Ntext Decimal:has precision and scale Decimal(p,s) Numeric(p,s) P = total digits in a number S = number of digits after decimal point Eg. Numeric(4,2) can store 22.56 and so on Money: Data like 23.2234 Money Smallmoney Date: Smalldatetime – Range – 1-1-1900 to 6-6-2079 Datetime - Range – 1-1-1753 to 31-12-9999 Binary: Binary Varbinary Image Misc: Uniqueidentifier – Unique id – can be accessed and modified through function getUid() and setUid() Cursor – Special data type meant for row by row operation Sql_variant – Generic data types Table – table data type – stores table data Timestamp – Uniqe value in a database
  3. Arithmetic : +, -, *, /, % Assignment : = Comparison : &amp;lt;, &amp;gt;, &amp;lt;=, &amp;gt;= &amp;lt;&amp;gt;, =, !=, !&amp;lt;, !&amp;gt; Logical : AND, OR, NOT, IN, LIKE, BETWEEN, ANY, ALL, EXISTS, SOME String : Concatenation (+) Unary : -, +, ~ Bitwise: &amp;, |, ^
  4. To execute a statement in MS SQL, Select the statement and Click on the Execute button in the query analyser or press F5
  5. To select distinct rows, we need to use the distinct key word Select distinct name from orders; Orders -------- IdName --------- 1Ram 2Krish 3Ram 4Raj Will fetch Ram Krish Raj Select count(name) from orders;will yield the result as 4 Sum, max, min, avg can be applied only on numbers. Select sum(id) from orders will yield the result as 10 Select max(id) from orders will yield the result as 4 Select min(id) from orders will yield the result as 1 Select avg(id) from orders will yield the result as 2.5 Order by Select * from Orders order by name; 2Krish 4Raj 1Ram 3Ram Select * from Orders order by name desc; 3Ram 1Ram 4Raj 2Krish Where: Select * from orders where name = ‘Raj’; will result in IdName --------- 4 Raj Having: Select Name, count(id) from Orders Group by name Having count(id) &amp;gt; 1 This will display names and number of occurances of name from orders table if the number of occurances Is &amp;gt; 1 Namecount(id) Ram 2 If we miss the having, it simply displays Name and occurance of name in the table. Select Name, count(id) from Orders Group by name Namecount(id) Krish1 Raj1 Ram2
  6. create table Student ( sid int, sname varchar(20) ) Drop table student;
  7. insert into Student values(1,&amp;apos;Ramu&amp;apos;) insert into Student(sid,sname) values(6,&amp;apos;Raj&amp;apos;) insert into Student(sid) values(2) insert into Student(sname) values(&amp;apos;Seetha&amp;apos;)
  8. update student set sid=3 This will set sid =3 for all students update student set sid=1 where sname=&amp;apos;Ramu‘ This will set sid as 1 only for Ramu
  9. delete from student where sid between 1 and 3 This will delete students with sid 1,2,3
  10. Add new column: Alter table test add grade char(1); Modify a column data type: Alter table test alter column grade varchar(10); Delete a column: Alter table test drop column grade;
  11. A table can have only one clustered index and any number of non clustered index (upto 249) Unique index – When a unique index exists, the Database Engine checks for duplicate values each time data is added by a insert operations. Insert operations that would generate duplicate key values are rolled back, and the Database Engine displays an error message. Clustered index - clustered index can be rebuilt or reorganized on demand to control table fragmentation. A clustered index can also be created on a view. This improves the performance. Non clustered index - Creates an index that specifies the logical ordering of a table. With a nonclustered index, the physical order of the data rows is independent of their indexed order.