Select * fromlol--Top KeywordsSelect Top 3 * fromlol--query first three linesSelect Top 3 * fromlolwhereAge> A --Join conditionsSelect Top 3Name,wuqi fromlolwhereAge> A ----keyword DISTINCT query different items go to weightSelect distinctName fromlol--querying rows with different names--ORDER by AscendingSelect * fromlolOrder byAgeASC--AscendingSelect * fromlolOrder byAgedesc--Descending default does not write the words ascendingSelect * fromlolOrder byAge,sex--based on the age of sex and not change the results of the first group, and then sorted by the second group--Grouping group by+ columns--grouping that column only shows which columnSelectAge fromlolGroup byAge--grouping on a column is equivalent to going back to display--Select column from LOL GROUP BY columnGo--operator query results for age plus 5 yearsSelect * fromlolwhereAge+5> ---arithmetic operator +-*/%--comparison operators >< >= <=! = <>!>!<--logical operator and or not (modifier, cannot be used alone)--modifier all some--all meanings are combined with a range to use--in what rangeSelect * fromlolwhereAgeinch( A, at)--represents equal to the first parameter or equal to the second argumentSelect * fromlolwhereAge not inch( A, at)--The age is not within this range not the modifier effect--find information about students who are not in the range of age (height is 164)--SELECT * FROM student where high=164--SELECT * FROM student where age!=23--subquery: Query a column of data using a query statement and then use it as a parameter to the query criteria of the other query--find information about students who are not in the range of height (age is 22 years old)--SELECT * FROM student where is high not in (select High from student where age=22)--Note is a column of information as a parameterGo--FOREIGN key: Constrained table called foreign key table, constrained table called primary key table--to add foreign keys, you first have to have a primary key table--to delete data from the primary key table, you must first delete the data from the Foreign key table--The column of the data source that is the foreign key must be a unique key (must be a primary key or unique)Create TableTeacher (TNOint Primary Key not NULL, Tnamevarchar)Create TableStudent1 (Snoint Primary Key, Snamevarchar, TNOint ReferencesTeacher (TNO),--constrained by TNO in teacher tableCidvarchar( -)Unique --It can't be repeated.)
Alter TablelolAddHighint --add a column that is allowed to be emptyAlter TablelolDrop columnZsx--Delete a columnSelect * fromlolUpdatelolSetGuishudi=' All true teachings '' whereCode=2Insert intololValues('man Wang Wushi','male', *,'Queen Mother','Fuxi Gossip','Ill- conceived mountain',185)Select * fromlolwhereAge>= - andHigh>= theSelect * fromlolOrder byHighdescSelect* fromlolwhereAge not inch(SelectAge fromlolwhereHigh=188)SelectName fromlolwhereHigh=(Select Max(high) fromLOL)--the name of the tallest personSelect COUNT(*) fromlol--How many data are in the tableexecsp_rename'Lol.duixiang','wife','column' --Modify column names--The format is Exec sp_rename ' table. Original column name ', ' new column name ', ' column '
SQL Server Learning Note 2