SQL

Database Queries in SQL

Hello All,

Hope this post finds you in good health and spirit.

Structured Query Language, abbreviated as SQL, is a domain-specific language used in programming and designed for managing data held in a relational database management system, or for stream processing in a relational data stream management system.

An good developer must be familiar with a few commands in SQL because it is such a strong development tool. The SQL queries listed below are important for coding and optimization. Almost every system that interacts with a SQL database will be affected by each query in the SQL tutorial.

Database Queries in SQL

These are some of the commonly used database queries in SQL.

SELECT – database query used to extract data from a table.
CREATE DATABASE – database query used to create a new database. DROP DATABASE – database query used to delete a database.
CREATE TABLE – database query used to create a table in the specified database.
ALTER TABLE – database query used to modify an existing table in the specified database
DROP TABLE – database query used to delete an existing table in the specified database
CREATE INDEX – Index creation query.
CREATE VIEW – View creation query.
DROP VIEW – View deletion query.
CREATE PROCEDURE – Procedure creation query.
CREATE FUNCTION – Function creation query.
DROP PROCEDURE – Procedure deletion query.
DROP FUNCTION – Function deletion query. Example of Query in a Database

We will be looking at some SELECT examples of a query in a database, as this is the most common command.

SELECT * FROM employeeTable WHERE emp_no = ‘12’;

This query filters out results that do not match a specified search.

SELECT * FROM sys.objects WHERE object_id=object_id(‘<table name>’);

This database query will list all the columns of the table whose name matches the argument.

Database Queries Examples

The following are some database queries examples that deal with creating tables, in a bit more advanced fashion.

Create a table with a primary key called “ID”.
CREATE TABLE table_name (
PRIMARY KEY(column_name)
);
Create a table with a non-unique index called “IDX” on column_name.
CREATE INDEX idx_name ON table_name (column_name);

Create a view with the name “VIEW1” that can be used to query data from table1. The view is created on columns column1 and column2. It must return the same number of rows as the underlying table, and it must return the same data type. In this case, we will return the maximum value for each column in the underlying table when queried against the view. The following query will be used to populate our view: CREATE VIEW view1 AS SELECT MAX(column1), MAX(column2) FROM table1;

Common Database Queries

Some more common database queries you will need are: 1) The Maximum Value for a Column. SELECT MAX(column_name) FROM table_name 2) The Minimum Value for a Column. SELECT MIN(column_name) FROM table_name 3) The Count of Rows in a Table.

SELECT COUNT(*) FROM table_name;

DBMS Queries with Examples

DBMS stands for DataBase Management System. Following are some DBMS queries with examples; these are very important for developers and database admins alike. 1. The List of Values for a Column. SELECT column_name, column_commalist FROM table_name; 2. The Difference between two Column Values.

SELECT column_name(+) FROM table_name WHERE column_name(+) != value;

III. The List of Unique Values for a Column.

SELECT DISTINCT column_name FROM table_name;

So, that’s all in this blog. I will meet you soon with next stuff .Have a nice day !!!

Recommended contents

Guys please don’t forget to like and share the post.Also join our WindowsTechno Community and where you can post your queries/doubts and our experts will address them .

You can also share the feedback on below windows techno email id.

If you have any questions feel free to contact us on admin@windowstechno.com also follow us on facebook@windowstechno to get updates about new blog posts.

How useful was this post?

Click on a star to rate it!

As you found this post useful...

Follow us on social media!

Was this article helpful?
YesNo

Leave a Reply

Back to top button