SQL -- Structured Query Language
SQL is a Structured Query Language for storing, manipulating and
retrieving data in database.
RDBMS (relational database management system)
Oracle, MS SQL SERVER, MySQL, DB2, PostgressSQL
DDL: Data Definition Language
Create: table, database
Create table testdb (No varchar(20),passport_No varchar(20),phone_No Varchar(10));
Create database testdb;
Instance ---------------- RAM
No of databases
No of tables
No of column
Alter:
ALTER TABLE [dbo].[testdb] ADD Email varchar(255);
select * from [dbo].[testdb]
Truncate:
Truncate table testdb ;
Rename:
ALTER DATABASE MyRapid_DB_1 MODIFY NAME = MyRapid_DB;
Drop:
drop table testdb;
DML - Data manipulating Language
Insert:
insert [dbo].[testdb] values(103,'S07676578',0116102456,'naveen@gmail.com');
insert [dbo].[testdb] values(102,'S07676567',011616745,'kagitha@gmail.com');
Update:
update testdb set Phone_no='011615788' where No='102';
update testdb set Email='kagithanaveen@gmail.com' where No='103';
delete:
delete from testdb where email='naveen@gmail.com';
DRL – Data retrieval language
Select:
select * from [dbo].[testdb]
Commit:
update testdb set Email='kagithanaveen1@gmail.com' where No='103';
commit;
DCL: Data Control language
GRANT:
grant select,update,insert,delete on [BookStore].[dbo].[testdb] to public;
REVOKE:
revoke select,update,insert,delete on [BookStore].[dbo].[testdb] from public;
MS SQL SERVER:
List the system Databases?
Master
Model
MSDB – SQL agent/jobs
Tempdb
Resource
Distribution
Master:
the database that records the existence of all other databases and the location of
those database files and records the initialization information for SQL Server
Model:
the template database that SQL Server uses to create new databases
MSDB – SQL agent/jobs:
stores information of all SQL Agent jobs as their configuration and their execution
history
Tempdb:
a global resource that holds: Temporary user objects that are explicitly created
Resource:
The Resource database is a read-only database that contains all the system objects that are
included with SQL Server.
Distribution:
stores metadata and history data for all types of replications, and transactions for
transactional replication
Create database testdb
create table tests(phone varchar(12),name varchar(22),id varchar(22))
select * from tests
select * from [dbo].[DimProduct]
SELECT ReorderPoint FROM [dbo].[DimProduct]
WHERE ReorderPoint BETWEEN 750 AND 500;
SELECT ReorderPoint FROM [dbo].[DimProduct]
ORDER BY ReorderPoint DESC
SELECT DISTINCT ReorderPoint FROM [dbo].[DimProduct]
SELECT COUNT(DISTINCT ReorderPoint) FROM [dbo].[DimProduct]

SQL_--_Structured_Query_Language[1].docx

  • 1.
    SQL -- StructuredQuery Language SQL is a Structured Query Language for storing, manipulating and retrieving data in database. RDBMS (relational database management system) Oracle, MS SQL SERVER, MySQL, DB2, PostgressSQL DDL: Data Definition Language Create: table, database Create table testdb (No varchar(20),passport_No varchar(20),phone_No Varchar(10)); Create database testdb;
  • 2.
    Instance ---------------- RAM Noof databases No of tables No of column Alter: ALTER TABLE [dbo].[testdb] ADD Email varchar(255); select * from [dbo].[testdb] Truncate: Truncate table testdb ; Rename: ALTER DATABASE MyRapid_DB_1 MODIFY NAME = MyRapid_DB; Drop: drop table testdb; DML - Data manipulating Language Insert: insert [dbo].[testdb] values(103,'S07676578',0116102456,'naveen@gmail.com'); insert [dbo].[testdb] values(102,'S07676567',011616745,'kagitha@gmail.com');
  • 3.
    Update: update testdb setPhone_no='011615788' where No='102'; update testdb set Email='kagithanaveen@gmail.com' where No='103'; delete: delete from testdb where email='naveen@gmail.com'; DRL – Data retrieval language Select: select * from [dbo].[testdb] Commit: update testdb set Email='kagithanaveen1@gmail.com' where No='103'; commit; DCL: Data Control language GRANT: grant select,update,insert,delete on [BookStore].[dbo].[testdb] to public; REVOKE: revoke select,update,insert,delete on [BookStore].[dbo].[testdb] from public;
  • 4.
    MS SQL SERVER: Listthe system Databases? Master Model MSDB – SQL agent/jobs Tempdb Resource Distribution Master: the database that records the existence of all other databases and the location of those database files and records the initialization information for SQL Server Model: the template database that SQL Server uses to create new databases MSDB – SQL agent/jobs: stores information of all SQL Agent jobs as their configuration and their execution history Tempdb: a global resource that holds: Temporary user objects that are explicitly created Resource: The Resource database is a read-only database that contains all the system objects that are included with SQL Server. Distribution: stores metadata and history data for all types of replications, and transactions for transactional replication Create database testdb create table tests(phone varchar(12),name varchar(22),id varchar(22))
  • 5.
    select * fromtests select * from [dbo].[DimProduct] SELECT ReorderPoint FROM [dbo].[DimProduct] WHERE ReorderPoint BETWEEN 750 AND 500; SELECT ReorderPoint FROM [dbo].[DimProduct] ORDER BY ReorderPoint DESC SELECT DISTINCT ReorderPoint FROM [dbo].[DimProduct] SELECT COUNT(DISTINCT ReorderPoint) FROM [dbo].[DimProduct]