Skip to main content

   SQL--Standard Query Language.

     It is standard language for relational database management system developed by Microsoft. It is standard language for storing,manipulating and retrieving the data in database. Some common relational database management systems that uses SQL are: Oracle,My SQL, Access,etc. 

Database-

  • It is compiler for all SQL object like tables,stored procedures,triggers,functions,etc.
  • Two types of Database- 1. System Database   2. User Defined Database.
  • System Databases are -  Master (in which predefined objects which can be used to achieve some functionalities) , Msdb (report services like Email) ,  Model (structure which we get or table or any other objects) , Tempdb (it is temporary tables).  
  • User defined Database - which we created in our application.
To work in SQL we have two different ways:

  1. Graphical Way- In SQL Sever Graph database to  help simplify the process of modeling data that contain complex many-to-many and hierarchical relationship. At its most basic a graph database is a collection of node and edges that work together to define various type of relationship.
  2. Query-It is used to retrieve meaningful and relevant information from database.When building a structure we pull a data from tables and fields. The fields are columns in the tables while the actual data makes up from the rows.    
Commands-

  • DDL-(Data Definition Language) -These commands affects on schema or structure.                                                              Truncate,Create,Alter,Drop,etc are DDL commands.
  • DML-(Data Manipulation Language) -  Any command which affects on data or row.                                                             select,Insert,Update,Delete,etc. are DML commands.
  • DCL-(Data Control Command)- Any command which affects on permission.                                                                        Grant,Revoke,etc. are DCL Commands.
  • TCL(Transaction Control Language)- Any command which affects on transaction.                                                                        Commit,Rollback,etc. are TCL commands.
Use of Commands-       
  • Create table- To create table
  • Select- To select record
  • Insert Into- To insert into
  • Update- To update record
  • Delete- To delete record
  • Alter- To add column 
  • Drop- To delete table (to delete schema)
  • Truncate- Use to drop and recreates table(it is faster than delete)
Let's create small table :




In above image we can see that there is table. Explanation is as follow:
  • First we have to create one database like in above example, Demo is database with DDL cmd  create.(create database Demo)
  • After that we have to use Demo database by  use cmd.(use Demo)
  • Then we create a table withe DDL create cmd. ie. create table Student. Here Student is name of the table.(create table Student)
  • Now in that table we have to create some columns. By image there are four columns with name- RollNo , FirstName , LastName , Address. With their data types.
  • At last we have to write Select * from Studedent. This means we get the structure of table or output of table when we enter data into it.(Select*from Student)
  • In result we can see that table with column names only.

Constraints:
  1. Null Constraint  - Null is a special marker used in SQL to indicate that the data value dose not exist in the database. i.e. Null means absence of value.
  2.  Unique constraint - It is used to ensure that no duplicate values will be inserted into a specific column. We can create multiple unique constraints over the table. It allow single null value.
  3. Default Constraint - We can provide default value to the column. When  we do not provide any value to column then it set default value.
  4. Check constraint - It is rule or condition that help to check the inserted or updated data values to tables. Eg. Age should not be less than 10 and greater than 40.
  5. Cascading Referential Integrity -  It is allow to define the action when a user tries to delete or update a key or which foreign key exist.
Key:
  1. Candidate Key - It is used to ensure data integrity by preventing duplicate data.
  2. primary Key  - It is used to  ensure the uniqueness in the column.There is only one primary key over the table because it create clustered index and it sort the data by that column in the table.Primary key does not allow any null value.
  3. Alternate Key - It is a key associated with one or more columns whose values uniquely identify every row in the table. i.e. Alternate key are those candidate key which are not primary key.
  4. Composite Key - A primary key having two or more attributes is called composite key.it is combination of two or more columns.
  5. Foreign Key - Foreign is a field in one table,,that refers to the primary key in another table. the table with primary key is called parent table and the table with foreign key is called child table.
 Operators:   An operator is reserved word or character used primarily in an SQL statements Where clause perform operations. These operators used to specify conditions in a SQL statements.
  1. Arithmetic operator - + , - , * , / , %
  2. Comparison Operator - = , != , <> , > , < , >= , < = , !< , !>
  3. Logical Operators -


Operator Description
All Use to operate a value to all values in another value set
And And operator allow the existence of multiple conditions in SQL where clause
Any This is used to compare a value to any applicable value as per condition
Between Between used to search for value
Exists Used to search for the presence of a row in a specified table that
Like like operator used to compare a value to similar value
In This is used to compare a value to list of literal values that have been specified
Not The not reverse the meaning of the logical operator with which is used
Or The or is used to combine multiple conditions with where clause
Is Null This is used to compare the value with a null value
Unique The unique operator searches every row of a specified table for uniqueness

Comments

Post a Comment