0% found this document useful (0 votes)
3 views3 pages

Working With Databases (Lecture Notes)

The document explains the differences between DBMS and databases, MySQL and SQL, and char and varchar data types. It outlines the steps for working with databases using SQL commands, including creating databases and tables, inserting values, retrieving data, updating records, and deleting entries. Key examples and syntax for each operation are provided to illustrate the concepts.

Uploaded by

shambhavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Working With Databases (Lecture Notes)

The document explains the differences between DBMS and databases, MySQL and SQL, and char and varchar data types. It outlines the steps for working with databases using SQL commands, including creating databases and tables, inserting values, retrieving data, updating records, and deleting entries. Key examples and syntax for each operation are provided to illustrate the concepts.

Uploaded by

shambhavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Difference b/w the following:

DBMS vs Database
----------------
DBMS stands for Database Management System. It is a "software" which help us to
create and work with databases.
Ex:- MySql
Database is a collection of tables/relations. You need create a database using SQL
commands and further use these commands to work on database in various ways
SQL command:- Syntax: CREATE DATABASE databasename;

MySQL vs SQL
------------
MySQL is a DBMS that helps to create and work with Databases. It can create
Databases either manually or using SQL commands.
SQL stands for Structured Query Language which contains various commands that help
us to work with databases and its related tables/relations

char vs varchar
---------------
char stores only fixed-length character string data types whereas varchar stores
variable-length string where an upper limit of length is specified

CHAR stores small set of characters


VARCHAR stores variable set of characters. probably large length strings

Ex:- CREATE TABLE Employee(Name VARCHAR(50), Grade CHAR(4));

Steps for working with Databases (Manually or using SQL Commands)


-----------------------------------------------------------------

Here, we are using SQL commands:

Note: SQL is a case-insensitive language like wise HTML. PHP is a case-sensitive


language

1. Create a Database

Syntax: CREATE DATABASE databasename;

create database student;

2. Select Database

Syntax: USE database_name;

Ex: use student;

3. Create table

Syntax:
CREATE TABLE table_name
(
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Ex:
create table marks
(
roll_no int primary key not null,
name varchar(255),
course varchar(255),
subject varchar(50),
score float
);

If to check the structure/schema of the created/existing table, use the command


DESCRIBE
Syntax:- DESCRIBE table_name;
Ex:- describe marks;

4. Insert value into a table

Syntax:
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2,
value3, ...);

Ex:
insert into marks(roll_no,name,course,subject,score) values(1,'Ravi Kumar','BA
Prog V Sem','PHP Programming',81.0);

or

Syntax:
INSERT INTO table_name VALUES (value1, value2, value3, ...);

EX:
insert into marks values(2,'Chitra Tripathi','BA Prog V Sem','PHP
Programming',67.0);

5. Fetch/Retrieve the values from the created table

Retrieve values of particular column/field based on given condition


Syntax:
SELECT column1/field1, column2/field2,....,columnn/fieldn FROM table_name WHERE
<condition>;

Ex:- select name from marks where roll_no=1;

or

Retrieve values of all columns/fields in the table

Syntax:
SELECT * FROM table_name;

Ex:- select * from marks;

6. Update row-entry/record in a table

Syntax:
UPDATE table_name
SET column1 = updated_value, column2 = updated_value, ...
WHERE condition;

Ex:
update marks set name='Ravi Kapoor' where roll_no = 1;

7. Delete row-entry/record from table

Syntax:
DELETE FROM table_name WHERE condition;

EX:
delete from marks where roll_no=1;

You might also like