SlideShare a Scribd company logo
1 of 13
Database Training for Developers


                 --
          Bhavesh Thakkar
       Database Administrator
*Go through*
•   Database Design.
•   Create Database.
•   Create User.
•   Grant User Privileges.
•   Create Database Objects.
•   Apply Indexes on tables.
•   Efficient way to write stored procedures.
•   Execution Plan/Explain Plan for Query
    Optimization.
Design of database.

• Understand the requirement of the system.
• Read document and imagine about growth of
  database and relation with each entity
• Create E-R Diagrams
Create Database.

• Create Database based on understanding of
  system.
• Use E-R diagram to create objects.
Create User.

• Every database connected /accessed by users
  and logins.
• Create User with necessary privileges to
  connect and operation on database.
Create Database Objects

• Create tables with necessary columns. Add at least one
  Primary key and if system generated then put auto
  incremented.
• Create Views based on Table. Put hint WITH (NOLOCK)
  .Grant Select permission to View not Table for security
  reason.
• Created extra non-clustered index on most accessed
  columns.
• Use SSMS Performance monitor after running database.SQL
  Server gather statistics and get the information of missing
  indexes. Based on this statistics also can indexes creation
  possible after release of system.
• Add description of tables and columns.
How to write stored procedures

• Minimum sized header of stored procedure. It should be limited
  text.
• For e.g.
•
        /*********************************************
•                *Created By:Bhavesh Thakkar
•                     *Description:”Wow” It’s too short.
• *Modified Info:2013-01-29..Oh..! God Still small size require in it.
• *execution code.must return value.for only select statement.not for
  DML
•
•                     */
• Continued..
How to write stored procedures

•   2. Deallocate/Close Cursor at the end of sps.
•   3. Try to avoid Cursors in stored procedure.
•   4. Use proper naming to declare.
•   Select * into #AllJPG from tmf_meterfiles
    where FileType=1
•   Declare @SQLQuery
•   Declare @SQLExtension
•      5. Do not use * instead of column name in
    Select Query.
•   6. Drop # (hash) tables at the end of query.
How to write stored procedures
•   7. Use functions to avoid complexity.
•   Suppose, Get Film Name producer name and billing amount
•
•   --Without Function
•   Select f.filmname,fw.WorkerName,b.totalammount
•   From dbo.tBilling b inner join dbo.tfilm f
•   on b.filmid=f.filmid
•   inner join dbo.tFilmWorkers fw
•   on f.ProducerId=fw.wid
•
•   --With Function
•
•   Select dbo.fnGetFilmName(filmId) FilmName,dbo.fnGetWorkerName(WID)
    WorkerName,b.totalammount
•   From dbo.tBilling b
Efficient way to optimize queries and
           stored procedures
• This topic become much easier when we write
  stored procedures and queries proper way
  that discussed in topic 7.
• Still, Query consumes memory and execution
  time more then we should go with Query
  tuning.
• Follow these steps...
• Continued..
Efficient way to optimize queries and
           stored procedures
• Check Estimated Execution/Explain Plan
Efficient way to optimize queries and
           stored procedures
• 2. Check indexes on tables that used in
  queries.
• 3. Check enough memory allocated to SQL
  Server.
• 4. Create Indexed views if useful to your
  query.
• 5. Partition Large sized tables.
Efficient way to optimize queries and
              stored procedures
•   --[usp_GetTvTrackDetails_Android] 'Mexico',10, 7462, '2012-OCT-01 6:00:00 AM'
•   SET STATISTICS TIME ON
•   Declare @CountryName as varchar(50),
•   @LiveMinDiff as int,
•   @BlankImgSize as int=7462,
•   @StartDateTime as smalldatetime,
•   @InActiveMeterFlagDays as int = -2
•
•   Declare @EndDateTime as smalldatetime
•   SET @LiveMinDiff=10
•   SET @CountryName='Mexico'
•   SET @StartDateTime='2012-MAY-01 6:00:00 AM'
•
•   Declare @EndDateTime as smalldatetime
•   Set @EndDateTime=dateadd(Day,1,@StartDateTime)
•   --Get Footer Value
•
•       -- RowNo,MeterNo,TheFileName,TheFilePath,FileDateTime,FileSize
•   select * into #Temp_MeterFiles from tMF_MeterFiles WITH(NOLOCK) where MeterNo IN (SELECT MeterNo FROM TMETERS WHERE COUNTRY=@CountryName and IsConfirm=1)
•    And FILEDATETIME between @StartDateTime and @EndDateTime and filedatetime<= getutcdate()
•
•   Select * from
•    (select Count(RowNo) as ImgCount from #Temp_MeterFiles where TheFileName LIKE '%.jpg')T1
•   ,
•    (select count(distinct MeterNo) as AvtiveHomes from #Temp_MeterFiles where TheFileName LIKE '%.jpg')T2
•   ,
•    (select count(distinct MeterNo) as ActiveMeters from #Temp_MeterFiles)T3
•   ,
•    (select count(distinct MeterNo) as LiveHomes from #Temp_MeterFiles where TheFileName LIKE '%.jpg' AND dateDiff(minute,FILEDATETIME,getutcdate())<=@LiveMinDiff)T4
•   ,
•    (select Count(*) as MeterCount from tmeters where country=@CountryName)T5
•      ,
•   (Select Count(MeterNo) as ConfirmMeterCount from tMeters where IsConfirm=1)T7
•
•
•   Select top 1 TheFileName,TheFilePath from #Temp_MeterFiles where TheFileName LIKE '%.jpg' and FileSize>@BlankImgSize order by FileDateTime desc
•
•
•   Select distinct MeterNo from #Temp_MeterFiles where TheFileName LIKE '%.jpg' AND dateDiff(minute,FILEDATETIME,getutcdate())<=@LiveMinDiff
•
•      select meterNo as InActiveMeters into #Temp_InActiveMeters from tMeters where country=@countryName and MeterNo not in (Select MeterNo from #Temp_MeterFiles) and
    IsConfirm=1
•

More Related Content

What's hot

PyCon DE 2013 - Table Partitioning with Django
PyCon DE 2013 - Table Partitioning with DjangoPyCon DE 2013 - Table Partitioning with Django
PyCon DE 2013 - Table Partitioning with DjangoMax Tepkeev
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2ShepHertz
 
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)Matt Fuller
 
Desired state-configuration-ravikanth-august-2013-vtc india
Desired state-configuration-ravikanth-august-2013-vtc indiaDesired state-configuration-ravikanth-august-2013-vtc india
Desired state-configuration-ravikanth-august-2013-vtc indiaRavikanth Chaganti
 
Spark performance tuning eng
Spark performance tuning engSpark performance tuning eng
Spark performance tuning enghaiteam
 
Automating Workflows for Analytics Pipelines
Automating Workflows for Analytics PipelinesAutomating Workflows for Analytics Pipelines
Automating Workflows for Analytics PipelinesSadayuki Furuhashi
 

What's hot (7)

PyCon DE 2013 - Table Partitioning with Django
PyCon DE 2013 - Table Partitioning with DjangoPyCon DE 2013 - Table Partitioning with Django
PyCon DE 2013 - Table Partitioning with Django
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2
 
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
Presto Testing Tools: Benchto & Tempto (Presto Boston Meetup 10062015)
 
Desired state-configuration-ravikanth-august-2013-vtc india
Desired state-configuration-ravikanth-august-2013-vtc indiaDesired state-configuration-ravikanth-august-2013-vtc india
Desired state-configuration-ravikanth-august-2013-vtc india
 
Spark performance tuning eng
Spark performance tuning engSpark performance tuning eng
Spark performance tuning eng
 
Automating Workflows for Analytics Pipelines
Automating Workflows for Analytics PipelinesAutomating Workflows for Analytics Pipelines
Automating Workflows for Analytics Pipelines
 
Orms vs Micro-ORMs
Orms vs Micro-ORMsOrms vs Micro-ORMs
Orms vs Micro-ORMs
 

Viewers also liked

Universal design for learning
Universal design for learningUniversal design for learning
Universal design for learningBeihong WU
 
Nuevo presentación de microsoft power point
Nuevo presentación de microsoft power pointNuevo presentación de microsoft power point
Nuevo presentación de microsoft power pointSamuel Kuartas
 
Initial presentation
Initial presentationInitial presentation
Initial presentationrabiha01
 
SCG-putting-proposal
SCG-putting-proposal SCG-putting-proposal
SCG-putting-proposal Wes-Craft
 
Excalibur --
Excalibur --Excalibur --
Excalibur --Wes-Craft
 
Pasos de investigación
Pasos de investigaciónPasos de investigación
Pasos de investigaciónSamuel Kuartas
 
Wdr2013 oct7 final light
Wdr2013 oct7 final lightWdr2013 oct7 final light
Wdr2013 oct7 final lightCaroline Austin
 
Putting Course proposal for Sun City Grand
Putting Course proposal for Sun City GrandPutting Course proposal for Sun City Grand
Putting Course proposal for Sun City GrandWes-Craft
 
Introduccion a Investigacion de Operaciones - IO
Introduccion a Investigacion de Operaciones - IOIntroduccion a Investigacion de Operaciones - IO
Introduccion a Investigacion de Operaciones - IOYesith Valencia
 

Viewers also liked (18)

Portafolio
PortafolioPortafolio
Portafolio
 
Excalibur -
Excalibur -Excalibur -
Excalibur -
 
Music Video Pitch
Music Video PitchMusic Video Pitch
Music Video Pitch
 
Universal design for learning
Universal design for learningUniversal design for learning
Universal design for learning
 
Sql Server troubleshooting guide
Sql Server troubleshooting guideSql Server troubleshooting guide
Sql Server troubleshooting guide
 
Nuevo presentación de microsoft power point
Nuevo presentación de microsoft power pointNuevo presentación de microsoft power point
Nuevo presentación de microsoft power point
 
Sweetx honey catalogue v1.2
Sweetx honey   catalogue v1.2Sweetx honey   catalogue v1.2
Sweetx honey catalogue v1.2
 
Initial presentation
Initial presentationInitial presentation
Initial presentation
 
Music video pitch
Music video pitchMusic video pitch
Music video pitch
 
SCG-putting-proposal
SCG-putting-proposal SCG-putting-proposal
SCG-putting-proposal
 
Excalibur --
Excalibur --Excalibur --
Excalibur --
 
Sweetx honey catalogue v1.4
Sweetx honey   catalogue v1.4Sweetx honey   catalogue v1.4
Sweetx honey catalogue v1.4
 
CFP Evaluation 2016
CFP Evaluation 2016CFP Evaluation 2016
CFP Evaluation 2016
 
Pasos de investigación
Pasos de investigaciónPasos de investigación
Pasos de investigación
 
Wdr2013 oct7 final light
Wdr2013 oct7 final lightWdr2013 oct7 final light
Wdr2013 oct7 final light
 
Putting Course proposal for Sun City Grand
Putting Course proposal for Sun City GrandPutting Course proposal for Sun City Grand
Putting Course proposal for Sun City Grand
 
XML
XMLXML
XML
 
Introduccion a Investigacion de Operaciones - IO
Introduccion a Investigacion de Operaciones - IOIntroduccion a Investigacion de Operaciones - IO
Introduccion a Investigacion de Operaciones - IO
 

Similar to Database Training for Developers: Design, Create, Optimize SQL

SQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and ProfilingSQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and ProfilingAbouzar Noori
 
Domino Server Health - Monitoring and Managing
 Domino Server Health - Monitoring and Managing Domino Server Health - Monitoring and Managing
Domino Server Health - Monitoring and ManagingGabriella Davis
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS BackendLaurent Cerveau
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional testHarry Zheng
 
The inherent complexity of stream processing
The inherent complexity of stream processingThe inherent complexity of stream processing
The inherent complexity of stream processingnathanmarz
 
SQL Server 2008 For Developers
SQL Server 2008 For DevelopersSQL Server 2008 For Developers
SQL Server 2008 For DevelopersJohn Sterrett
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 
SharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi VončinaSharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi VončinaSPC Adriatics
 
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails AppSrijan Technologies
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsfMao Geng
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptFramgia Vietnam
 
Remote DBA Experts SQL Server 2008 New Features
Remote DBA Experts SQL Server 2008 New FeaturesRemote DBA Experts SQL Server 2008 New Features
Remote DBA Experts SQL Server 2008 New FeaturesRemote DBA Experts
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlMydbops
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevMigration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevAltinity Ltd
 
Implementing Tables and Views.pptx
Implementing Tables and Views.pptxImplementing Tables and Views.pptx
Implementing Tables and Views.pptxLuisManuelUrbinaAmad
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Jan Helke
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1sqlserver.co.il
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core HacksDaniel Niedergesäß
 
PostgreSQL Performance Problems: Monitoring and Alerting
PostgreSQL Performance Problems: Monitoring and AlertingPostgreSQL Performance Problems: Monitoring and Alerting
PostgreSQL Performance Problems: Monitoring and AlertingGrant Fritchey
 
10x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp0210x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp02promethius
 

Similar to Database Training for Developers: Design, Create, Optimize SQL (20)

SQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and ProfilingSQL Server 2014 Monitoring and Profiling
SQL Server 2014 Monitoring and Profiling
 
Domino Server Health - Monitoring and Managing
 Domino Server Health - Monitoring and Managing Domino Server Health - Monitoring and Managing
Domino Server Health - Monitoring and Managing
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional test
 
The inherent complexity of stream processing
The inherent complexity of stream processingThe inherent complexity of stream processing
The inherent complexity of stream processing
 
SQL Server 2008 For Developers
SQL Server 2008 For DevelopersSQL Server 2008 For Developers
SQL Server 2008 For Developers
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9
 
SharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi VončinaSharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi Vončina
 
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
[Srijan Wednesday Webinar] Easy Performance Wins for Your Rails App
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
 
Remote DBA Experts SQL Server 2008 New Features
Remote DBA Experts SQL Server 2008 New FeaturesRemote DBA Experts SQL Server 2008 New Features
Remote DBA Experts SQL Server 2008 New Features
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in Postgresql
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevMigration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
 
Implementing Tables and Views.pptx
Implementing Tables and Views.pptxImplementing Tables and Views.pptx
Implementing Tables and Views.pptx
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']
 
SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1SQL Explore 2012: P&T Part 1
SQL Explore 2012: P&T Part 1
 
Magento performance feat. core Hacks
Magento performance feat. core HacksMagento performance feat. core Hacks
Magento performance feat. core Hacks
 
PostgreSQL Performance Problems: Monitoring and Alerting
PostgreSQL Performance Problems: Monitoring and AlertingPostgreSQL Performance Problems: Monitoring and Alerting
PostgreSQL Performance Problems: Monitoring and Alerting
 
10x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp0210x improvement-mysql-100419105218-phpapp02
10x improvement-mysql-100419105218-phpapp02
 

Recently uploaded

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
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
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
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 

Recently uploaded (20)

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
 
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
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
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...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 

Database Training for Developers: Design, Create, Optimize SQL

  • 1. Database Training for Developers -- Bhavesh Thakkar Database Administrator
  • 2. *Go through* • Database Design. • Create Database. • Create User. • Grant User Privileges. • Create Database Objects. • Apply Indexes on tables. • Efficient way to write stored procedures. • Execution Plan/Explain Plan for Query Optimization.
  • 3. Design of database. • Understand the requirement of the system. • Read document and imagine about growth of database and relation with each entity • Create E-R Diagrams
  • 4. Create Database. • Create Database based on understanding of system. • Use E-R diagram to create objects.
  • 5. Create User. • Every database connected /accessed by users and logins. • Create User with necessary privileges to connect and operation on database.
  • 6. Create Database Objects • Create tables with necessary columns. Add at least one Primary key and if system generated then put auto incremented. • Create Views based on Table. Put hint WITH (NOLOCK) .Grant Select permission to View not Table for security reason. • Created extra non-clustered index on most accessed columns. • Use SSMS Performance monitor after running database.SQL Server gather statistics and get the information of missing indexes. Based on this statistics also can indexes creation possible after release of system. • Add description of tables and columns.
  • 7. How to write stored procedures • Minimum sized header of stored procedure. It should be limited text. • For e.g. • /********************************************* • *Created By:Bhavesh Thakkar • *Description:”Wow” It’s too short. • *Modified Info:2013-01-29..Oh..! God Still small size require in it. • *execution code.must return value.for only select statement.not for DML • • */ • Continued..
  • 8. How to write stored procedures • 2. Deallocate/Close Cursor at the end of sps. • 3. Try to avoid Cursors in stored procedure. • 4. Use proper naming to declare. • Select * into #AllJPG from tmf_meterfiles where FileType=1 • Declare @SQLQuery • Declare @SQLExtension • 5. Do not use * instead of column name in Select Query. • 6. Drop # (hash) tables at the end of query.
  • 9. How to write stored procedures • 7. Use functions to avoid complexity. • Suppose, Get Film Name producer name and billing amount • • --Without Function • Select f.filmname,fw.WorkerName,b.totalammount • From dbo.tBilling b inner join dbo.tfilm f • on b.filmid=f.filmid • inner join dbo.tFilmWorkers fw • on f.ProducerId=fw.wid • • --With Function • • Select dbo.fnGetFilmName(filmId) FilmName,dbo.fnGetWorkerName(WID) WorkerName,b.totalammount • From dbo.tBilling b
  • 10. Efficient way to optimize queries and stored procedures • This topic become much easier when we write stored procedures and queries proper way that discussed in topic 7. • Still, Query consumes memory and execution time more then we should go with Query tuning. • Follow these steps... • Continued..
  • 11. Efficient way to optimize queries and stored procedures • Check Estimated Execution/Explain Plan
  • 12. Efficient way to optimize queries and stored procedures • 2. Check indexes on tables that used in queries. • 3. Check enough memory allocated to SQL Server. • 4. Create Indexed views if useful to your query. • 5. Partition Large sized tables.
  • 13. Efficient way to optimize queries and stored procedures • --[usp_GetTvTrackDetails_Android] 'Mexico',10, 7462, '2012-OCT-01 6:00:00 AM' • SET STATISTICS TIME ON • Declare @CountryName as varchar(50), • @LiveMinDiff as int, • @BlankImgSize as int=7462, • @StartDateTime as smalldatetime, • @InActiveMeterFlagDays as int = -2 • • Declare @EndDateTime as smalldatetime • SET @LiveMinDiff=10 • SET @CountryName='Mexico' • SET @StartDateTime='2012-MAY-01 6:00:00 AM' • • Declare @EndDateTime as smalldatetime • Set @EndDateTime=dateadd(Day,1,@StartDateTime) • --Get Footer Value • • -- RowNo,MeterNo,TheFileName,TheFilePath,FileDateTime,FileSize • select * into #Temp_MeterFiles from tMF_MeterFiles WITH(NOLOCK) where MeterNo IN (SELECT MeterNo FROM TMETERS WHERE COUNTRY=@CountryName and IsConfirm=1) • And FILEDATETIME between @StartDateTime and @EndDateTime and filedatetime<= getutcdate() • • Select * from • (select Count(RowNo) as ImgCount from #Temp_MeterFiles where TheFileName LIKE '%.jpg')T1 • , • (select count(distinct MeterNo) as AvtiveHomes from #Temp_MeterFiles where TheFileName LIKE '%.jpg')T2 • , • (select count(distinct MeterNo) as ActiveMeters from #Temp_MeterFiles)T3 • , • (select count(distinct MeterNo) as LiveHomes from #Temp_MeterFiles where TheFileName LIKE '%.jpg' AND dateDiff(minute,FILEDATETIME,getutcdate())<=@LiveMinDiff)T4 • , • (select Count(*) as MeterCount from tmeters where country=@CountryName)T5 • , • (Select Count(MeterNo) as ConfirmMeterCount from tMeters where IsConfirm=1)T7 • • • Select top 1 TheFileName,TheFilePath from #Temp_MeterFiles where TheFileName LIKE '%.jpg' and FileSize>@BlankImgSize order by FileDateTime desc • • • Select distinct MeterNo from #Temp_MeterFiles where TheFileName LIKE '%.jpg' AND dateDiff(minute,FILEDATETIME,getutcdate())<=@LiveMinDiff • • select meterNo as InActiveMeters into #Temp_InActiveMeters from tMeters where country=@countryName and MeterNo not in (Select MeterNo from #Temp_MeterFiles) and IsConfirm=1 •