SQLBasics
A repo for basic MySQL Commands and for storing Lab Assignments.
Show Databases
SHOW DATABASES;
Create Databases
CREATE DATABASE database_name;
Use Databases
USE database_name;
Drop Databases
DROP DATABASE database_name;
Show Tables
SHOW TABLES;
Describe Table
DESCRIBE table_name
or
DESC table_name
Show Table (query)
SELECT * FROM table_name;
Create Table
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
....
);
Describe Structure of a Table
DESCRIBE table_name;
Drop Table
DROP TABLE table_name;
Truncate Table
TRUNCATE TABLE table_name;
Alter Table (Add Column)
ALTER TABLE table_name
ADD column_name datatype;
Alter Table (Drop Column)
ALTER TABLE table_name
DROP COLUMN column_name;
Alter Table (Modify Column)
ALTER TABLE table_name
MODIFY COLUMN column_name datatype;
or
ALTER TABLE table_name
ALTER COLUMN column_name datatype;
Constraints
CREATE TABLE Persons (
ID int PRIMARY KEY,
FirstName varchar(255) NOT NULL,
AadharNo int UNIQUE,
City varchar(255) DEFAULT 'Mumbai',
Personid int IDENTITY(1,1)
Age int,
CHECK (Age>=18)
);
Constraints - Foreign Key
CREATE TABLE Orders (
OrderID int PRIMARY KEY,
OrderNumber int NOT NULL,
ID int,
FOREIGN KEY (ID) REFERENCES Persons(ID)
);
SQL Queries
Client_master
product_master
salesman_master
sales_order
sales_order_details
challan_header
challan_details
Assignment List
Feel free to refer my personal code repos.
Create ISSUE if you find any. PULL REQUESTS are welcomed.
Please use it responsibly. Thank you!