Structured Query Language, or SQL is a standardized query language for requesting information from a database. The original version called SEQUEL (structured English query language) was designed by an IBM research center in 1974 and 1975. SQL is often used across all applications to build reports, get relevant data to the user by querying tables. SQL is the engine, which works behind all front-end applications to get the results, user wants to see and a good or bad SQL statement defines the performance of the application.
Why Use SQL?
The beauty of SQL is that anyone working at a company that stores data in a relational database can use it.
If you work for a software company and want to pull usage data on your customers, you can do that using SQL. If you work for an ecommerce company that has data about customer purchases, you can use SQL to find out which customers are purchasing which products etc.,
In this approach to learning SQL we’ll divide the problem of writing a query into three simple steps:
· The first step is to pose the question. This will be in the form of a phrase
· In the second step we’ll work toward taking our question and transforming it into a SQL statement.
· In the third step, we’ll translate our mapped information into SQL
What are Databases?
There are a lot of Database available in the market such as MS Access, Oracle etc. Database fundamentally comprises of a set of tables containing data in rows & columns. Each column in a table corresponds to a category of data – customer name or address. While each row contains a data value for the intersecting column. To be able to get data from these databases easily, there has to be a way where we could get information from all these databases using the same method. For this purpose, SQL was developed. It is a kind of language, which enables us to ask all our queries to a database without getting bothered about the exact type of database.
Statements/commands defining SQL
There are various syntax and commands which are used in SQL to generate output. Let’s discuss SELECT, INSERT, UPDATE and DELETE statements and see how they are used. The SELECT statement lets you select a set of values from a table in a database. The Insert statement lets us insert information into a database, DELETE to remove records or any particular column values from a database and UPDATE statement will replace those values specified in SQL with new values mentioned.
Let me explain the above concept with the help of an example; Say we have a table named “Employee” with the below columns and rows.
First SQL Query
Let’s write our first SQL statements to retrieve different information based on the business needs.
SELECT FirstName, LastName FROM Employee – will display FirstName LastName of all three records from the table above.
SELECT * FROM Employee where Age > 26 – will display below record.
Interpreting SQL Statements
Let’s look into INSERT, UPDATE and DELETE statement with the help of an example to see what each statement will fetch.
INSERT INTO Employee Values (‘Chiraag’,’Mohan’,’25’,’Houston’) – will insert a new row at the bottom of the table “Employee” consisting of the values mentioned in the parentheses.
UPDATE Employee SET Age = ’50’, City = ‘Mumbai’ WHERE (LastName = ‘Kumari’)
Would change Priyanka Kumari’s age from 29 to 50 and would make him shift his residence from ‘Bangalore’ to ‘Mumbai’.
DELETE from Employee where LastName = ‘Kumari’ Would remove the entire record which represents any person whose LastName is ‘Kumari’.
· SQL Queries can be used to retrieve large amounts of records from a database quickly and efficiently.
· SQL databases use long-established standard, which is being adopted by ANSI & ISO.
· Using standard SQ, it is easier to manage database systems without having to write substantial amount of code.
Since the dawn of computing,amounts of data has been growing exponentially, constantly asking more from our data storage, processing, and analysis technology. In the past decade, this caused software developers to cast aside SQL as a relic that couldn’t scale with these growing data volumes, leading to the rise of NoSQL: MapReduce and Bigtable, Cassandra, MongoDB, and more.
Yet today SQL is resurging.