??????????
??????
????CREATE TABLE <????>(<????> <????????>[?м??????????????]
????[??<????> <????????>[?м??????????????]]…);
?????м????????????????NULL[?????]??NOT NULL[?????]??UNIQUE[]??????????????????????????????????????
???????
????-- ?????????
????CREATE TABLE Student
????(
????Id INT NOT NULL UNIQUE PRIMARY KEY??
????Name VARCHAR(20) NOT NULL??
????Age INT NULL??
????Gender VARCHAR(4) NULL
????);
?????????
??????
????DROP TABLE <????>;
???????
????-- ????????
????DROP TABLE Student;
????????
??????
????TRUNCATE TABLE <????>;
???????
????-- ????????
????TRUNCATE TABLE Student;
????????
??????
????-- ?????
????ALERT TABLE <????> [ADD <??????> <????????>[?м??????????????]]
????-- ?????
????ALERT TABLE <????> [DROP COLUMN <????>]
????-- ?????
????ALERT TABLE <????> [MODIFY COLUMN <????> <????????> [?м??????????????]]
???????
????-- ????????`Phone`??
????ALERT TABLE Student ADD Phone VARCHAR(15) NULL;
????-- ????????`Phone`??
????ALERT TABLE Student DROP COLUMN Phone;
????-- ????????`Phone`??
????ALERT TABLE Student MODIFY Phone VARCHAR(13) NULL;
????SQL??????
??????
????SELECT [ALL|DISTINCT] <????б???>[??<????б???>]…
????FROM <???????????>[??<???????????>]…
????[WHERE <????????>]
????[GROUP BY <????> [HAVING <????????>]]
????[ORDER BY <????> [ASC|DESC]…]
????SQL??????????SELECT??FROM??WHERE??GROUP BY??HAVING??ORDER BY??SELECT??FROM???????HAVING????????GROUP BY??????á?
???????
????SELECT * FROM Student
????WHERE Id>10
????GROUP BY Age HAVING AVG(Age) > 20
????ORDER BY Id DESC
????SQL???????
??????
????-- ?????????????
????INSERT INTO <????> [(?????[???????]…)] VALUES (????[??????]…);
????-- ?????????????????????
????INSERT INTO <????> [(?????[???????]…)] SELECT ??????;
???????
????-- ?????????????
????INSERT INTO Student (Name??Age??Gender) VALUES ('Andy'??30??'?');
????-- ?????????????????????
????INSERT INTO Student (Name??Age??Gender)
????SELECT Name??Age??Gender FROM Student_T WHERE Id >10;
????SQL???????
??????
????UPDATE <????> SET ????=?????[??????=?????…]
????[WHERE ????????]
???????
????-- ??Id??(10??100)??Age??1
????UPDATE Student SET Age= Age+1 WHERE Id>10 AND Id<100
????SQL??????
??????
????DELETE FROM <????> [WHERE ????????]
???????
????-- ???IdС??10????????
????DELETE FROM Student WHERE Id<10;
????????????
??????
????CREATE [UNIQUE] [CLUSTER] INDEX <??????> ON <????>(<????>[<????>][??<????>[<????>]]…);
????UNIQUE???????????????????????????????????
????CLUSTER????????????????????????
???????????ASC(????)??DESC(????)?????ASC
???????
????-- ?????????????????????Id????????
????CREATE UNIQUE INDEX INDEX_SId ON Student (Id DESC);
????-- ?????????????????????Id??Name????????
????CREATE UNIQUE INDEX INDEX_SId_SName ON Student (Id DESC??Name DESC);
???????????
??????
????DROP INDEX <??????>;
???????
????-- ???????????? INDEX_SId
????DROP INDEX INDEX_SId;
???????????
??????
????CREATE VIEW <?????>
????AS SELECT ??????
????[WITH CHECK OPTION]
?????????????????????κ?SELECT?????????????????ORDER BY????DISTINCT????
????WITH CHECK OPTION???????UPDATE??INSERT??DELETE??????????????
???????
????CREATE VIEW VIEW_Stu_Man
????AS SELECT * FROM Student WHERE Gender = '??'
????WITH CHECK OPTION
??????????
??????
????DROP VIEW <?????>;
???????
????DROP VIEW VIEW_Stu_Man;
????SQL????????
?????????????????????????洢??????DBA????????
????SQL?????????SELECT??INSERT??UPDATE??DELETE
??????
????-- 1.???
????GRANT <???>[??<???>]…
????[ON <????????> <??????>]
????TO <???>[??<???>]…
????[WITH GRANT OPTION]
????-- 2.??????
????REVOKE <???>[??<???>]…
????[ON <????????> <??????>]
????FROM <???>[??<???>]…
????WITH GRANT OPTION??????????????????????????????????????
???????
????-- ???
????GRANT SELECT??INSERT??UPDATE ON TABLE TO USER_Admin WITH GRANT OPTION
????-- ??????
????REVOKE SELECT??INSERT??UPDATE ON TABLE FROM USER_Admin