SQL Tutorial
SQL Tutorial provides in-depth knowledge about the Database Management using MS SQL Server, MySQL Server. To understand more about SQL Server, MySQL Server or MongoDB, you must have basic understanding of SQL Programs for Practice.
What is SQL ?
- SQL stands for Structured Query Language
- SQL is used to store and fetch data in the database
- SQL can be sub classified into DQL – Data Query Language, DML – Data Manipulation Language, DDL – Data Definition Language, TCL – Transaction Control Language, DCL – Data Control Language
What are the DQL(Data Query Language) ?
- SELECT – This allows to get data from the database based on certain conditions which can be provided in this query
What are the DDL(Data Definition Language) ?
- CREATE – This creates a new table or database
- ALTER – This updates the structure of the table, adding/removing/updating a column etc
- TRUNCATE – This deletes all the data in the table and resets the auto increment counter to 0
- DROP – This removes the table from the group of tables in a database
- COMMENT – This adds comments to a table column
- RENAME – This renames the name of the existing table in the database
What are the DML(Data Manipulation Language) ?
- INSERT – This inserts the row in the table
- UPDATE – This updates the data in the table, updating a column value of a row etc
- DELETE – This deletes the data in the table, deleting one or more rows based on a condition
- LOCK – This attains a lock on the table
What are the DML(Data Control Language) ?
- GRANT – This grants privileges to user on tables, views, procedures
- REVOKE – This revokes privileges from user on tables, views, procedures
What are the TCL(Transaction Control Language) ?
- BEGIN – This starts a new transaction
- COMMIT – This commits a transaction, so all the queries executed are saved
- ROLLBACK – This rollbacks or undoes the set of queries executed the transaction till the provided savepoint.(It is more like a restoring of your system to a older version)
- SAVEPOINT – This helps to create a version so that if required to undo, we can mention this version to be undone till
- SET TRANSACTION – This specifies the type of transaction(SET TRANSACTION [ READ WRITE | READ ONLY ]);
List of SQL Programs for Practice
Below you will find the list of SQL programs, this will help to become a Database Developer or a DBA(Database Administrator)
Basic SQL programs for Practice | Database Practice with examples
- Write the query to get the branch and branch wise total(sum) admission fees, display it in ascending order according to admission fees
- Write the query to get no of students joined with respect to year and month from tblStudent table
- Write the query to get branch, no of students in a branch, total admission fees with respect to a branch from tblStudent table order by admission fees descending
- Write the query to get branch wise average admission fees from “tblStudent” table order by admission fees ascending order
- Write a SQL statement to display all students information
- Write a SQL query to get unique branch from tblstudent table
- Write a SQL query to Get the first name, last name, current date, admission date and difference between current date and admission date in days
- Write a SQL query to get student details from tblStudent table whose admission year is “2016”
- Write a SQL query to get student details from tblStudent table whose admission month is ‘June’
- Write a SQL query to get student details from tblStudent table whose admission date is before January 31st
- Write a SQL query to get student details from tblStudent table whose admission date is after January 31st 2018
- Write a SQL query to get position of ‘v’ in name ‘David’ from tblstudent
- Write a SQL query to get only year part of admission date from tblStudent
- Write a SQL query to get only month part of admission date from tblStudent
- Write a SQL query to get list of all students whose first name start with ‘Ma’ or ‘Da’
- Write a SQL query to get length of FirstName from tblstudent
- Write a SQL query to get FristName from tblStudent table after replacing ‘a’ with ‘$’
- Write a SQL query to get FirstName, Lastname, Scholarship amount from tblStudent and tblScholarship table for all students even if they didn’t get Scolarship
- Write a SQL query to get firstname from tblstudent with Hello prefix
- Write a SQL query to get FirstName from tblstudent after removing white spaces from right side
- Write a SQL query to get FirstName from tblstudent after removing white spaces from left side
- Write a SQL query to get first name from tblstudent in upper case
- Write a SQL query to get first name from tblstudent in lower case
- Write a SQL query to get details whose firstname starts with name “David”
- Write a SQL query to get database date
- Write a SQL query to get all students details from the tblStudent table order by LastName Ascending and Admission fees descending
- Write a SQL query to get all students details from the tblStudent table order by FirstName Descending
- Write a SQL query to get all students details from the tblStudent table order by FirstName Ascending
- Write a SQL query to get all student details from tblstudent whose “FirstName” start with letter ‘d’
- Write a SQL query to get all student details from tblstudent whose “FirstName” ends with ‘a’
- Write a SQL query to get all student details from tblstudent whose “FirstName” contains ‘a’
- Write a SQL query to get all student details from tblStudent table whose admission date between ‘2016-01-01’ and ‘2018-01-01’
- Write a SQL query to get admission date and time from tblStudent table
- Write a SQL query to display sum of two numbers 10 and 15
- Write a SQL query to display firstname and branch of student, who belongs to the branch ‘Computer Engineering’
- Write a SQL query to display a string “Hello World!”
- Write a SQL query to combine firstname and lastname and display it as “Full Name”
- Write a SQL query get fristname from tblstudent not start with any single character between a-l
- Write a Sql query get first name, admission year, admission month and admission date from tblStudent table
- Write a SQL query get all students details from tblStudent whose first name starts with ‘m’ and name contains 4 letters
- Write a SQL query get all students details from tblStudent whose first name ends with ‘a’ and name contains 4 letters
- Write a query to select TOP Nth (any number) admission fees from tblStudent table
- Write a query to select TOP 2 Admission fees from tblStudent table
- Write a query to select second highest admission fees from “tblStudent” table
- Write a query to select Minimum Admission fees from tblStudent table
- Write a query to select highest Admission fees from tblStudent table
- Write a query to select FirstName, LastName from tblStudent table in singal column
- Write a Query to get the first name, last name, current date, admission date and difference between current date and admission date in year
- Write a Query to get the first name, last name, current date, admission date and difference between current date and admission date in month
- Write a query to get students details from “tblStudent” whose admission fees is less than 1200
- Write a query to get students details from “tblStudent” whose admission fees is greater than 1200
- Write a query to get students details from “tblStudent” whose admission fees is between 900 and 1500
- Write a Query to get only time part of the “AdmissionDate” from tblStudent
- Write a query to get how many students exist in tblstudent
- Write a query to get 5 % of admission fees from Michael, 10% of admission fees from John and for other 15 % of admission fees as ‘Deducted_Admission_fee’ from tblStudent table
- Write a Query to get “AdmissionDate” in “yyyy/mm/dd” format, ex- “2019/05/06”
- Write a Query to get “AdmissionDate” in “dd mmm yyyy” format, ex- “06 May 2019”
- Write a query to display only firstname and branch from table student
- Top 100 SQL server queries Interview questions | SQL server interview questions
- SQL Server Advanced Questions – ‘Join’
- MS SQL Queries to retrieve data from tables
- List of SQL Query questions on Top, Union, admission fees and Group by questions
- List of SQL Query questions on Datetime
- How to find out Microsoft SQL Server Enterprise Edition Expiration Date
- How can I remove duplicate rows from large table