MySQL SQL – Structured Query Language

SQL – Structured Query Language

SQL – Structured Query Language

SQL is an abbreviation for Structured Query Language, usually pronounced as separate letters “S-Q-L” or “Sequel“. SQL is a query language as reflected by its name, is used for database accessing and its modification which can include any operation like – Create data, Read data, Update Data, Delete Data etc.

SQL was developed by Donald D. Chamberlin and Raymond F. Boyce at IBM in the early 1970s. The first commercially available implementation of SQL was introduced in 1979, by Relational Software, Inc. (now Oracle) . Now, SQL is known as the standard RDBMS language.

SQL actually allows the user to work with data at logical level. SQL has a lot of operations to do with the databases, however when we start learning SQL, the basic operations we focus on are Select, Insert, Update and Delete.

SQL offers statements for a variety of operations, which include:

  • Querying/Selection of data
  • Insert, update and delete operations on rows in a table.
  • Create, replace, alter and drop object operations.
  • Controlling access to the database and its objects
  • Guaranteeing database consistency and integrity

All the major relational database management systems support SQL. SQL is platform independent and programs written in SQL are portable, hence, they can easily be moved from one database to another with very little modification. SQL is used widely both in web based and desktop based applications.

Now get some hands on practice, i.e., programming concepts.

“Hope you have gone through the database tutorial as it will let you understand the concept of rows and columns.”

As mentioned above “when we start learning SQL, the basic operations we focus on are Select, Insert, Update and Delete”. Let’s first start with learning syntax. SQL syntax depends on the type of statements (Select, Insert, Update and Delete).

SQL SELECT statement:

Syntax:

Explanation: To select (read/retrieve) any data from database we use SELECT followed by column names. If you need to select all the columns use “*” in place of .
Examples:

SQL INSERT statement:

Syntax: 

Explanation: To insert values in all columns, providing column names is not necessary instead data in values section will be inserted in the columns in sequence of table structure.
Examples:

SQL UPDATE statement:

Syntax: 

Explanation: To update values in a table we use conditions to update certain rows otherwise the update will be applied on all the rows.
Examples:

SQL DELETE statement:

Syntax: 

Explanation: To delete values from a table we use conditions to delete certain rows otherwise all the rows will be deleted.
Examples:

SQL statements explained above are used to manipulate data in the database. Now let’s have a look on the statements which define and change(alter) the structure of a database table.

SQL CREATE statement:

SQL CREATE statements are used to define or say create a table in a database which contain information of the number of columns and their data types.
Syntax:

Below is and example which created a table named ‘students’ with columns student_id of type integer cannot be NULL, student_name of type VARCHAR that can have maximum 100 characters which can’t be NULL and student_subject of type VARCHAR that can have maximum 100 characters
which can’t be NULL.
Example:

SQL ALTER statement:

SQL ALTER statements are used to make changes in the structure of any table. It can be any operation like: adding one or more columns, drop(deleting) columns, changing datatype or any other property of a column, making INDEX or any keys etc. It has a wide variety of operations but I am showing a ADD column and DROP column.

SQL ALTER statement to ADD new column:

TO ADD columns in a table structure ADD is used.
Syntax:

Below is and example in which I am adding more columns.
First I am adding a column named student_grade of type VARCHAR that can have maximum 20 characters which can’t be NULL.
After that, I added two columns named student_grade1 and student_grade3, both of type VARCHAR that can have maximum 10 characters having NULL as default value.
Example:

SQL ALTER statement to DROP columns:

To delete any column from table structure DROP is used.
Syntax:

Below is an example which added two columns in table named ‘students’, named student_grade and student_grade2, both of type VARCHAR that can have maximum 10 characters having NULL as default value.
Example:

Share your thoughts

avatar
  Subscribe  
Notify of