Learn SQL Commands (Part-1)

Mohammed Waseem
4 min readSep 25, 2022

T-SQL Commands for beginners

I will be using SQL Server Management Studio (SSMS)

Table Of Contents

  1. Create a Database
  2. Create a table
  3. Insert data into a table
  4. View data from the table
  5. View data by specific [Student Id]
  6. View data by specific [Student Name]
  7. View data by specific [Student Name] first character is ‘a’
  8. View data by specific [Student Name] the last character is ‘m’
  9. View Student in Descending order of [Student Id]
  10. Display the number of students in the table
  11. Display only [Student Name] from the table
  12. Insert data on a table with a Foreign key
  13. Display Name from the first table and subject, grades from the second table.
  14. Display the average grades of the student
  15. Display the average grades of the student in ascending order
  16. Display the average grades with different column names
  17. Display the Sum of the grades by Students

1. Create a database

It can be viewed in object explorer

2. Create a table

3. Insert data into the table

[Student Id] will be automatically added due to identity(1,1) means starting from 1 and increment by 1 -> (1,2,3,4……) and it will also be unique because it is a primary key.

4. View data from the table

5. View data by specific [Student Id]

6. View data by specific [Student Name]

7. View data by specific [Student Name] first character is ‘a’

8. View data by specific [Student Name] the last character is ‘m’

9. View Student in Descending order of [Student Id]

10. Display the number of students in the table

11. Display only [Student Name] from the table

I will be using another table for displaying more commands. The grading table contains students' grades in different subjects.

A foreign key is a key that has a primary key on another table, here it is [Student Id] from the Student table

And after inserting data I have the following data on the table

12. Insert data on a table with a Foreign key

13. Display Name from the first table and subject, grades from the second table

14. Display the average grades of the student

Note: Group by is required on using the Avg() function

15. Display the average grades of the student in ascending order

16. Display the average grades with different column names

17. Display the Sum of the grades by Students

Follow for more

Feel free to reach me or comment here

www.linkedin.com/in/mwaseemaw

--

--