0% found this document useful (0 votes)
9 views

SQL Database

Uploaded by

1122.awaissaleem
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

SQL Database

Uploaded by

1122.awaissaleem
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL Related Database

Database is a collection of related data and data is a collection of facts and figures that can be
processed to produce information.

Types of Data:

1) .Relational Database(SQL):
Store data in objects called Tables.
They have consist of rows and coloums
Fixed data structure.
They have vertically scalable.
Support complex Queries.
Normalized.
2) Non-Relational Databse(NOSQL)
Store data in any from.
For example key-Value Paris,Graphs,Document(JSON,XML etc,)
Cannot be scaled horizontally.

DATABASE Managemnet System:


Database Management System (DBMS) is a collection of programs which enables its user to access
a database, manipulate data,reporting/representation of data.

Means: database management system is like a software jo database sa top krna ka


lia use hota ha means database sa interact krna ka li use karta hain.
Rational Database management system :

Rational database ma data aps ma connected hota ha with the help of tables or ya tables
relationship ka zarie aps ma contected hota Normal data base ma asa ni hota hota ha as ma
data primary keys or foreign keys ka zare aps ma contected hota ha

Example:MySQL SQL server,PostgreSQL SQL Oracle etc…

Ya sara database ak ho query language per base karta hain hain jo SQL ha structured Query
language ha

SQL:

SQL stand for Structured Query Language.


SQL is a standard Language for accessing,managing and manipulating databases.
Used to perform CURD operations.

Primary keys hum kasi bi chez ko uniquely identify use krna ka li use kata hain.

Relationship in Tables/Database:

Ak Employee ki ak hi salary ho sakti ha as li as ma ak hi relationship bana ga jo ka one to one ho ga


Salary wala table ko hum employee wala table ma bi rak sakta tha ni kia ku ka hum ni chata koi user
as ki persnol info daka as li hum as ko side per rak data hein

IMportant: Employe wala table ma employee ak primary key ha jo ka unique ha or dosra table
EmployeeSalry wala ha jo ka jo ka employees wala table ki primary keys use kr rha hain on keys ko
hum foroeign keys kata haein.

Means ak table ki primary keys dosra table ma use krna wala table ki keys foreign keys kata hain.
Ak employee ka double ya as ziada bi table ho sakta hein as ka alag sa table bana ga ku ka agar ak
employee ka 4 number howa tu baku ka na howa tu fer table tu karab ho j aga or ya normalizaiton ka
rule ka kalaf ho ga as la ak or table bana dia ga

Database Queries
SQL database non sql database ha jo ka

Create Database query:


CREATE DATABASE sample_db
Create Tables:
CREATE TABLE Books(
BookID INT PRIMARY KEY,
Title VARCHAR(50),
PublishedYear INT
);

Add Table from the outside of table:


Agr table ap na koi or add krna ha tu

ALTER TABLE Books


ADD Author varchar(50);

Select this command and add an other table in the database from the outside.

DELETE COLOUM from the outside of table:


CREATE TABLE Books(
BookID INT PRIMARY KEY,
Title VARCHAR(50),
PublishedYear INT
);

ALTER TABLE Books


DROP COLUMN Author

CHANGE FROM COLOUM type IN TABLE:not


null
ALTER TABLE Books
ALTER COLUMN PublishedYear VARCHAR NOT NULL

Now you have to see that PublishedYear has data type has int now after change
with the varchar string.

Insert Data into the Table:


insert into Books(Bookid,Title,publishedYear)
values(1,'introduction to programing',2020)

Check Data into the Table:


Select *from Books;
Keyword in SQL DATABASE:
NOT NULL: UNIQUE : PRIMARY KEY: DEFAULT FOREIGN KEY : INDEX :

How can unique, default IDENTITY keyword:


CREATE TABLE student (
studentid INT PRIMARY KEY IDENTITY(1,1),

-- The 'studentid column is an integer, serves as the


primary key, and auto-increments starting from 1.

Name VARCHAR(50) UNIQUE,

-- The 'Name' column is a variable-length string with a


maximum length of 50 characters, and it must be unique.

Age INT CHECK (Age >= 10 AND Age <= 25),


-- The 'Age' column is an integer with a constraint that
ensures values are between 10 and 25 inclusive.

class VARCHAR(50) DEFAULT 'bsse'

-- The 'class' column is a variable-length string with a


maximum length of 50 characters, defaulting to 'bsse'.
);

How can use Constraints keyword:


create table student(
studenid int ,
[Name] varchar(50),
Age int check(Age>=10 AND Age<=250),
class varchar(50) default 'bsse',

Constraint pk_student primary key(studenid),


Constraint UN_Name unique([Name]),
Constraint Age check (Age>=10 AND Age<100)

);

How can delete Constraints keyword:


alter table student
DROP CONSTRAINT pk_student,

drop constraint DF__student__class__17F790F9;


--deleted by default value:
\ kj

How can handle NULL or NOT NULL keyword:


alter table student
ALTER COLUMN [NAME] VARCHAR(50) null

You might also like