Create database schema:
CREATE DATABASE DB_NAME;
Create database if not exists db_name;
DROP DATABASE DB_NAME;
Drop database if exists db_name;
Show databases:
show tables;
USE DB_NAME;
Create a table:
USE db_name;
CREATE TABLE TABLE_NAME(
column_name1 datatype constraint,
column_name2 datatype constraint,
column_name3 datatype constraint
)
Example:
Create table student(
id INT PRIMARY KEY,
name VARCHAR(50),
age INT NOT NULL
);
Add data to tables:
INSERT INTO <TABLE_NAME> VALUES (COLUMN1_VALUE,COLUMN2_VALUE2,COLUMN3_VALUE);
Example:
INSERT INTO STUDENT VALUES (1,'SRI','36');
How to show all data of a table:
Select * from student;
SQL data types:
They define the type of values that can be stored in a column.
Types of SQL commands:
- DDL(data definition language): create, alter, truncate and drop
- DQL(data query language): Select
- DML(Data manupulation language): insert, update, delete
- DCL(data control language): Grant, Revoke permission to users.
- TCL(transaction control language): start transaction, commit, rollback
No comments:
Post a Comment