Skip to main content

Posts

Showing posts with the label MySQL

Database Creation & Table Manipulations

Database Creation & Table Manipulations   /*creating a database*/ create database school; /*show list of databases*/ show databases; /*to delete a database*/ drop database school; /*getting into a database school*/ use school; /*creating a table info Name Roll Section Subject */ create table info( name varchar(255), roll int, section varchar(1), subject varchar(25) ); /*to show list of tables present inside school database*/ show tables; /*to show the structure of table*/ desc info; /*to add a new column*/ alter table info add column house varchar(255); /*to add a class column after roll number*/ alter table info add column class int after roll; /*to add checking to class column*/ alter table info change column class class int check(class>0 and class<13) not null; /*to add primary key to class roll*/ alter table info change column roll roll int primary key; /*adding a default value to house set house to white house*/ alter table info change column house house varch...

MySQL Notes

MySQL Notes  show databases; use world; show tables; desc city; /to show all content of table city/ select * from city limit 10; /to show name,district,population/ select Name,District,Population from city limit 10; /order by helps to sort records in ascending/  select Name,Population from city order by Name asc limit 10; /order by in descending order for name/ select Name,Population from city order by Name desc limit 10; select Name,Population from city order by Population desc limit 10; select Name,Population from city order by Population asc; /order by in multiple column/ select Name,Population from city order by Name asc,Population desc; /where clause/ /* MySQL Logical Operators (i) AND (ii) OR (iii) BETWEEN (IV) NOT BETWEEN (V) LIKE (VI) NOT (VII) IS NULL (VIII) IN (IX) NOT IN  (X) IS NOT NULL (XI) < > <= >= != == (RELATIONAL OPERATORS) */ /* flow of writing mysql from -> where -> select -> order by */ select * from city limit 10; /display the di...

Important MySQL Queries using the World Database

The questions are written within /* */ show databases; use world; show tables; desc city; /*to show all content of table city*/ select * from city limit 10; /*to show name,district,population*/ select Name,District,Population from city limit 10; /*order by helps to sort records in ascending*/  select Name,Population from city order by Name asc limit 10; /*order by in descending order for name*/ select Name,Population from city order by Name desc limit 10; select Name,Population from city order by Population desc limit 10; select Name,Population from city order by Population asc; /*order by in multiple column*/ select Name,Population from city order by Name asc,Population desc; /*where clause*/ /* MySQL Logical Operators (i) AND (ii) OR (iii) BETWEEN (IV) NOT BETWEEN (V) LIKE (VI) NOT (VII) IS NULL (VIII) IN (IX) NOT IN  (X) IS NOT NULL (XI) < > <= >= != == (RELATIONAL OPERATORS) */ /* flow of writing mysql from -> where -> select -> order by */ select * fr...

Python MySQL CRUD Program

 Create python program to create,read,update and delete student details in MySQL database import mysql.connector as p con = p.connect(host="localhost",user="root",passwd="1234",database="useless") if con.is_connected():     print("Connection Established")     cur = con.cursor()     while True:         print("Enter 1 to add new student")         print("Enter 2 to update student details")         print("Enter 3 to delete student")         print("Enter 4 to show student list")         print("Enter 5 to exit system")         ch = int(input())         if ch==1: #insert data into table             ids = int(input("Enter the student id:"))             name = input("Enter the student name:")             cls = int(input("Enter student ...