Posts

Showing posts from December, 2025

Joins

Image
 Joins It help to stiches rows of two or more table together to provide meaningful information for business usecase. It is the best way to unite distributed information in database responsibly and help to safe space. To join to tables we must use right condition and criteria else cartition product will be created and will make the information inconsistent and will even leads to incorrect information generation. create table student_scaler( id int not null primary key auto_increment, name varchar(500) not null, b_id int, psp int); select * from student_scaler; insert into student_scaler (name, b_id, psp) values('Puneet Kumar Singh', 1, 90), ('Anubha Panwar', 1, 100), ('Devansh Singh', 2, 99), ('Sachin Panwar', 3, 96); create table batches_detail( b_id int not null primary key auto_increment, name varchar(500) ); select * from batches_detail; insert into batches_detail (name) values ('A'), ('B'), ('C'); -- joining student_scaler and...

CRUD

Image
 CRUD Create: Used to create database, table and to insert information in it. syntax: create database <database_name>; create table <table_name> ( columns_name datatype constrains ); insert into table_name (columns) values (value1); In insert into query you don't need to specify the columns. syntax: insert into film values(default, 'The Dark Knight', 'Batman fights the Joker', 2008, 1, NULL, 3,4.99,152, 19.99, 'PG-13', 'Trailer', default); But issue is that you need to remember the order and datatype of all columns and you cannot skip any column and can change their order as to understand the values table need to map the value with respective columns and hence it will consider the definition and will put information in same order hence always giving column names and then value is preferred. Drawbacks of using insert into command without column names in syntax: Not good practice and make query prone to errors as columns are not specified a...

Keys

Image
 Keys Candidate Key: Minimum super key is known as candidate key. As we need the minimum combination of columns or even if we have a single columns as unique identifier then that candidate column/columns can be considered as candidate key. example: If we have s_id and c_id and attendence as columns of a table where combination of s_id and c_id can identify a record but they can't identify the record independently then. s_id and c_id combination is candidate key as they are sufficient to identify the record. So combination of s_id, c_id and attendence can be a super key but it cannot be a candidate key as without attendence in a combination we can identify the record, so to identify a record s_id and c_id need to work together and they cannot be replacable. Primary Key: A column which can identify record uniquely is known as Primary Key, among candidate keys we need to choose only on column which can identify the record or we can say that minimum candidate key can be a primary key. ...