Tuesday, August 6, 2024

SQL - Create your database schema | Create a table |Add data to tables | SQL data types | Types of SQL commands

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:

  1. DDL(data definition language): create, alter, truncate and drop
  2. DQL(data query language): Select
  3. DML(Data manupulation language): insert, update, delete
  4. DCL(data control language): Grant, Revoke permission to users.
  5. TCL(transaction control  language): start transaction, commit, rollback





No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...