Home » SQL

Introduction to Structure Query Language (SQL)

Learn: What is SQL (Structure Query Language)? what are the basic terminologies of SQL?
Submitted by Shubham Singh Rajawat, on August 08, 2017

SQL (Structure Query language) is a standard database language for creating, maintaining, manipulating, and destroying relational database.

Query

A query is a request/question expressed in a formal way with intent to get some result .A 'SELECT is a query used for retrieval of data.

Relational Database

Relational database depends on relational data model in which data is arranged in columns and rows as relation (tables), having unique key in each row.

For Example: The table below shows a relation (table) of name Student which stores Enroll_No, Student_Name, DOB, Gender and Age.

SQL table example

Tuples

Rows of a relation are referred as tuples.

Attributes

Columns/fields of a relation are referred as attributes.

Degree

The number of attributes in a relation determines the degree of a relation. A relation with having ‘n’ attributes is said to be a relation of degree n. E.g. Degree of Student is 5.

Cardinality

he number of tuples in a relation determines the cardinality of a relation. E.g. Cardinality of Student is 3.

View

A view is a virtual table that does not exist on its own but it is derived from one or more tables.

Key

Any one attribute or a combination of attributes that uniquely identifies a record in the table is called key. E.g. in Student table Enroll_No is a key since it is unique for each student.

Types of keys in SQL

  1. Primary Key
    A primary key is a set of one or more attributes that can uniquely identify tuples within a relation.
  2. Candidate Key
    All attribute combination in a table that can serve as a primary key are candidate keys, as they are candidate for primary keys.
  3. Alternate Key
    A candidate key that is not a primary key is called alternate key.
  4. Foreign key
    A non-key attribute whose values are derived from the primary key of other table is called foreign key.
  5. Composite key
    A key that consist of more than one attribute to uniquely identify a tuple is called composite key.
  6. Super key
    Super is a set of one or more columns to uniquely identifies rows in a table.

Queries in SQL can be categories as:

1) Data Definition Language (DDL)

DDL provides command for defining relation schemas, deleting schemas and modifying relation schema i.e. it works on the structure of a relation schema for e.g. CREATE TABLE, ADD COLUMN, DROP etc.

2) Data Manipulation Language (DML)

DML provides command manipulate data in a table for e.g. INSERT, UPDATE, DELETE etc.

3) Data Query Language (DQL)

It is used to extract the data from table for e.g. SELECT.

4) Transaction Control Language (TCL)

It is used to manage transactions in database means they are used to manage changes made by DML statements for e.g. COMMIT, ROLLBACK etc.



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.