Professional Documents
Culture Documents
OPEN cursor_product;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @product_name + CAST(@list_price AS varchar);
FETCH NEXT FROM cursor_product INTO
@product_name,
@list_price;
END;
CLOSE cursor_product;
DEALLOCATE cursor_product;
Clustered indexes They don't have to be unique but it
certainly is encouraged.
The only time the data rows in a table are stored in sorted
order is when the table contains a clustered index. When a
table has a clustered index, the table is called a clustered
table
DÁTUM
DATE ÉÉÉÉ-HH-NN
DATETIME ÉÉÉÉ-HH-NN óó:pp:mm
ENUM felsorolás tipus. pl.:ENUM(érték1,érték2,érték3…)
MEGSZORÍTÁSOK
ON UPDATE NO ACTION
ON UPDATE CASCADE
SELECT
city,
COUNT (*)
FROM
sales.customers
WHERE
state = 'CA'
GROUP BY
city
HAVING
COUNT (*) > 10
ORDER BY
city;
In that case, WHERE is used to filter rows before grouping,
and HAVING is used to exclude records after grouping.
SUM
AVG
SELECT year,
COUNT(*) AS count
FROM tutorial.aapl_historical_stock_price
GROUP BY year;
SELECT
firstname,
lastname
FROM
sales.customers
ORDER BY
first_name DESC;
When should indexes be avoided?
Indexes should not be used on small tables.
Nonclustered
A nonclustered index can be defined on a table or
view with a clustered index or on a heap.
Each row in the index contains the key value and a
row locator.
This locator points to the data row in the
clustered index or heap having the key value.
The rows in the index are stored in the order of
the key values,
but the data rows are not guaranteed to be in any
particular order unless they are in a clustered
index.
Unique
A unique index ensures that the key contains no
duplicate values and therefore every row in the
table or view is in some way unique.
Full-text
A special type of token-based functional index that
is built and maintained by the Microsoft Full-Text
Engine for SQL Server. It provides efficient
support for sophisticated word searches in
character string data.