-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql
84 lines (59 loc) · 3.91 KB
/
sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
offset o or 1 rows
fetch next 10 rows only
also check majorshare holder tab more link for daily changes
primary key foreign key and composite key
************************************************************************************************
CREATE TABLE voting (
QuestionID NUMERIC,
MemberID NUMERIC,
PRIMARY KEY (QuestionID, MemberID)
);
The pair (QuestionID,MemberID) must then be unique for the table and neither value can be NULL. If you do a query like this:
SELECT * FROM voting WHERE QuestionID = 7
it will use the primary key's index. If however you do this:
SELECT * FROM voting WHERE MemberID = 7
it won't because to use a composite index requires using all the keys from the "left". If an index is on fields (A,B,C) and your criteria is on B and C then that index is of no use to you for that query. So choose from (QuestionID,MemberID) and (MemberID,QuestionID) whichever is most appropriate for how you will use the table.
If necessary, add an index on the other:
CREATE UNIQUE INDEX idx1 ON voting (MemberID, QuestionID);
*****************************************************************************************************
sql server has more then 8 type of indexes
A heap is a table without a clustered index.
SQL language is divided into four types of primary language statements: DML, DDL, DCL and TCL.
*************************************************************************************************************
DML (Data Manipulation Language)
DML statements affect records in a table. These are basic operations we perform on data such as selecting a few records from a table, inserting new records, deleting unnecessary records, and updating/modifying existing records.
DML statements include the following:
SELECT – select records from a table
INSERT – insert new records
UPDATE – update/Modify existing records
DELETE – delete existing records
DDL (Data Definition Language)
DDL statements are used to alter/modify a database or table structure and schema. These statements handle the design and storage of database objects.
CREATE – create a new Table, database, schema
ALTER – alter existing table, column description
DROP – delete existing objects from database
DCL (Data Control Language)
DCL statements control the level of access that users have on database objects.
GRANT – allows users to read/write on certain database objects
REVOKE – keeps users from read/write permission on database objects
TCL (Transaction Control Language)
TCL statements allow you to control and manage transactions to maintain the integrity of data within SQL statements.
BEGIN Transaction – opens a transaction
COMMIT Transaction – commits a transaction
ROLLBACK Transaction – ROLLBACK a transaction in case of any error
***********************************************************************************************************************************
http://www.tech-recipes.com/rx/category/database/
Every table needs a clustered index and a primary key. By default, the PK is clustered but it can be non-clustered if you want like you're done.
You have specified a non-clustered PK so the profiler suggests a clustered index...
Note: a table without a clustered index is called a "heap" because it's a pile of unstructured data..
https://stackoverflow.com/users/73226/martin-smith?tab=answers
SQL Server Query Performance Tuning
byGrant Fritchey
********************************************sql ebooks*****************************************************************
T-SQL Fundamentals (3rd Edition) by iztik bin gan
T-SQL Querying (Developer Reference)
Microsoft SQL Server 2012 T-SQL Fundamentals (Developer Reference)
SQL Practice Problems: 57 beginning, intermediate, and advanced challen
https://www.safaribooksonline.com/library/view/t-sql-fundamentals-third/9781509302031/
query writing order query execution order
select from where groupby having orderby from where groupby having select orderby