Introduction To SQL
What is SQL?
- SQL stands for Structured Query Language
- SQL is a standard language for accessing and manipulating databases.
- SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987.
- SQL keywords are NOT case sensitive.
- SQL can execute queries against a database, retrieve data from a database, insert records in a database, update records in a database, records from a database,create new databases, new tables.
- SQL can set permissions on tables, procedures, and views.
- An RDBMS database program (i.e. MS Access, SQL Server, MySQL).
- To use a server-side scripting language, like PHP or ASP.
- To use SQL to get the data you want to work with.
- To use HTML / CSS to style the page.
- RDBMS stands for Relational Database Management System.
- RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, Oracle, MySQL, and Microsoft Access.
- The data in RDBMS is stored in database objects called tables.
- A table is a collection of related data entries and it consists of columns and rows.
- Every table is broken up into smaller entities called fields.
- Example : The fields in the Student_info table consist of StudentID,StudentName, EmailId , Department and Grade.
- A field is a column in a table that is designed to maintain specific information about every record in the table.
- A record, also called a row, is each individual entry that exists in a table.
Database Tables:
A database most often contains one or more tables. Each table is identified by a name (EX: Student_info). Tables contain records (rows) with data.SQL Statements:
Most of the actions you need to perform on a database are done with SQL statements.
The following SQL statement selects all the records in the "student_info" table:
SELECT * FROM student_info;
Semicolon after SQL Statements?
- Some database systems require a semicolon at the end of each SQL statement.
- Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
Some of The Most Important SQL Commands
- SELECT - extracts data from a database
- UPDATE - updates data in a database
- DELETE - deletes data from a database
- INSERT INTO - inserts new data into a database
- CREATE DATABASE - creates a new database
- ALTER DATABASE - modifies a database
- CREATE TABLE - creates a new table
- ALTER TABLE - modifies a table
- DROP TABLE - deletes a table
- CREATE INDEX - creates an index (search key)
- DROP INDEX - deletes an index
SQL (Database) Management Tools:
The following SQL statement selects the "StudentName" and "percentage" columns from the "student_info" table:
Example:
SELECT StudentName, Percentage FROM student_info;
The following SQL statement selects all the columns from the "student_info" table:
Example:
SELECT * FROM student_info;
SQL SELECT DISTINCT Statement:
The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
Syntax:
SELECT DISTINCT column1, column2, ...
FROM table_name;
SQL WHERE Clause:
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified condition.
Syntax: SELECT column1, column2, ...
FROM table_name
WHERE condition;
Informative 👏
ReplyDeletePost a Comment