Some SQL basics

Create indexes on one or more columns in a table to help SQL server find the data quickly in a query.

An index helps speed up SELECT queries and WHERE clauses, but it slows down data input, with UPDATE and INSERT statements.

CREATE INDEX index_name
ON table_name (column_name);
CREATE INDEX index_name
on table_name (column1, column2);

You should only add those indexes for which you‘re sure that they‘re necessary. To determine the columns where you could put indexes on, you could:

  • add indexes to columns that are foreign keys
  • add indexes to columns that are often used in where clauses
  • add indexes to columns that are used in order by clauses.

SQL aggregate functions:

AVG(), MIN(), MAX(), COUNT()...


Some SQL basics

时间: 2024-08-26 14:09:26

Some SQL basics的相关文章

[SQL Basics] Indexes

An index is used to speed up searching in the database. By default, when you create this table, your data will be stored on disk and sorted by the "Id" primary key column. This default sort is called the "Clustered Index". Affects the

SQL查询初学者指南读书笔记(二)创建SQL查询

PARTII: SQL Basics CHAPTER 4Creating a Simple Query 介绍一种如何创建SQL语句的技术--"Request/Translation/Clean Up/SQL" The SELECT operationin SQL can be broken down into three smaller operations, which we will referto as the SELECT statement,the SELECT expres

Entity Framework Tutorial Basics(39):Raw SQL Query

Execute Native SQL Query You can execute native raw SQL query against the database using DBContext. You can execute the following types of queries: SQL query for entity types which returns particular types of entities SQL query for non-entity types w

SQL Server-聚焦NOT IN VS NOT EXISTS VS LEFT JOIN...IS NULL性能分析(十八)

前言 本节我们来综合比较NOT IN VS NOT EXISTS VS LEFT JOIN...IS NULL的性能,简短的内容,深入的理解,Always to review the basics. NOT IN.NOT EXISTS.LEFT JOIN...IS NULL性能分析 我们首先创建测试表 USE TSQL2012 GO CREATE SCHEMA [compare] CREATE TABLE [compare].t_left ( id INT NOT NULL PRIMARY KE

SQL Server-聚焦EXISTS AND IN性能分析(十六)

前言 前面我们学习了NOT EXISTS和NOT IN的比较,当然少不了EXISTS和IN的比较,所以本节我们来学习EXISTS和IN的比较,简短的内容,深入的理解,Always to review the basics. 初步探讨EXISTS和IN 我们创建表Table1并且取出前面创建BigTable表中的六条数据并插入其中,同时有一条数据重复,如下: CREATE TABLE Table1 (IntCol UNIQUEIDENTIFIER) Insert into Table1 (IntC

VITAM POST MORTEM – ANALYZING DEADLOCKED SCHEDULERS MINI DUMP FROM SQL SERVER

https://gennadny.wordpress.com/2014/11/ Since SQL Server 7.0, SQL Server has its own scheduling mechanism, In SQL 7.0 and 2000 it was called UMS (User Mode Scheduling) and later was renamed to SOS (SQL OS Scheduler). UMS\SOS is non-preemptive\coopera

SQL Server-聚焦使用视图若干限制/建议、视图查询性能问题,你懵逼了?(二十五)

前言 上一节我们简单讲述了表表达式的4种类型,这一系列我们来讲讲使用视图的限制,简短的内容,深入的理解,Always to review the basics. 避免在视图中使用ORDER BY 上一节我们也讲述了使用表表达式必须满足的3个要求,其中就有一个无法保证顺序,也就是说的ORDER BY的问题,我们还是重点看看在视图中的限制.在常规查询中对于排序我们是这样做的. USE AdventureWorks2012 GO SELECT * FROM Sales.SalesOrderDetail

SQL Server-聚焦LEFT JOIN...IS NULL AND NOT EXISTS性能分析(十七)

前言 本节我们来分析LEFT JOIN和NOT EXISTS,简短的内容,深入的理解,Always to review the basics. LEFT JOIN...IS NULL和NOT EXISTS分析 之前我们已经分析过IN查询在处理空值时是基于三值逻辑,只要子查询中存在空值此时则没有任何数据返回,而LEFT JOIN和NOT EXISTS无论子查询中有无空值上处理都是一样的,当然比较重要的是利用LEFT JOIN...IS NULL来检查NULL.基于二者返回的结果集是一样的,下面我们

Using databases and Structured Query Language (SQL)

//The code to create a database file and a table named Tracks with two columns in the database is as follows: 1 #!/usr/bin/python 2 import sqlite3 3 conn = sqlite3.connect('music.sqlite3') 4 cur = conn.cursor() 5 cur.execute('DROP TABLE IF EXISTS Tra