The fourth time in the database

Index
1. Index establishment

CREATE [UNIQUE] [CLUSTER] INDEX <索引名> 
ON <表名>(<列名>[<次序>][,<列名>[<次序>] ]);

Ascending ASC, Descending DESC, the default is ascending ASC

Example
Student table builds a unique index in ascending order of student number,

CREATE UNIQUE INDEX Stusno ON Student(Sno);

The Course table builds a unique index in ascending order of course number,

CREATE UNIQUE INDEX Coucno ON Course(Cno);

SC table builds a unique index in ascending order of student number and descending order of course number

CREATE UNIQUE INDEX SCno ON SC(Sno ASC,Cno DESC);

2. Modify the index

ALTER INDEX <旧索引名> RENAME TO <新索引名>;
EXEC sp_rename'SC.SCno','SCSno','index';

Insert picture description here
3. Delete the index

DROP INDEX SCSno ON SC

Data insertion

INSERT
INTO Student (Sno,Sname,Ssex,Sdept,Sage)
VALUES('201215128','王辉','男','IS',18);
INSERT 
INTO Student
VALUES('201215126','张成民','男',17,'CS');

Simple data query

1. Query the entire table

 SELECT * FROM Student;

2. Query specified attributes

SELECT Sname
FROM Student;

Guess you like

Origin blog.csdn.net/weixin_45958258/article/details/115289396