Content

  • SQL Introduction
  • RDBMS
  • Example : SQL Table
  • SQL Data Types
  • Create Database and Tables
  • SQL Select , Select distinct, Select top statements

SQL Introduction

  • SQL is a standard language for storing, manipulating and retrieving data in databases.
  • SQL stands for Structured Query Language.
  • SQL lets you access and manipulate databases by writing sql quries.
  • SQL can execute queries against a database.
  • SQL can retrieve data from a database.
  • SQL can insert / update / delete records in a database
  • SQL can create new databases
  • SQL can create new tables in a database
  • SQL can create stored procedures in a database

RDBMS

  • RDBMS stands for Relational Database Management System.
  • RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, 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.

Example of SQL Table

Name Email City
ABC ABC@gmail.com Kolhapur
DEF DEF@gmail.com Sangli
GHI GHI@gmail.com Satara
PQR PQR@gmail.com Pune

SQL Data Types

  • The data type of a column defines what value the column can hold: integer, character, money, date and time, binary,Image and so on.
  • Each column in a database table is required to have a name and a data type.
  • An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data.

Most used SQL data types :

  • VARCHAR(size) - to store character string data
  • INT(size) - to store numeric data
  • BIGINT(size) - to store numeric data
  • FLOAT(size,d) - numeric data with floating decimal point
  • DOUBLE(size,d) - A large number with a floating decimal point
  • DATE - to store date
  • DATETIME -to store date with time
  • nvarchar - to store Unicode string (we can give size as MAX for unlimited length)
  • varbinary - to store binary string
  • Image - to store encoded image

Create Database and Tables

To create database ->Database-> Create New in sql server management studio OR use below query

CREATE DATABASE databasename

To create table ->Database->Tables-New table OR use below query

CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... )

SQL Select , Select distinct, Select top statements

SQL select statement - is used to select data from a database

SELECT column1, column2, ... FROM table_name;

The SELECT DISTINCT statement - is used to return only distinct (different) values.

SELECT DISTINCT column1, column2, ... FROM table_name

Select top statement - is use to get top / limited records from database table

SELECT TOP number(s)(of records we want) FROM table_name