Use MyDataBase1
--* Indicates that all columns are displayed
--The query statement does not add a where condition to indicate that all rows are queried
Select *from tblstudent
---Query only some of the columns in the table
Select Tsid,tsname,tsgender from Tblstudent
---query only part of the row (using the Where condition to filter a portion of the row display), depending on the condition
SELECT * FROM Tblstudent where tsclassid=5
--Aliases for columns in the query result set
Select TSID as student number, tsname as student name, Tsgender as gender from Tblstudent
--can also be arranged in this way
Select
TSID as student number,
Tsname as student name,
Tsgender as Sex
From Tblstudent
Select
TSID ' (student number) ',--can output spaces
Tsname student Name,--Cannot output space
Tsgender Sex
From Tblstudent
Select
Student number =tsid,
Student name =tsname,
Sex =tsgender
From Tblstudent
Select
Student number =tsid,
Student name =tsname,
Sex =tsgender,
Marriage no = ' no '
From Tblstudent
--Not that select must be used in conjunction with from, you can use select alone
Select
Current system time =getdate ()
Select
Monitor = ' Yan Meng ',
Class flower = ' TBD ',
Ban Cao = ' TBD ',
Teacher in charge = ' song ci '
--distinct keyword, for results that have been queried and then remove duplicates
SELECT DISTINCT * from Tblstudent
Select distinct tsname,tsgender,tsaddress from tblstudent
sqlserver--Data Retrieval (query)