DEV Community

Cover image for Basic Sql Commands⏹️
BALAKRISHNA S
BALAKRISHNA S

Posted on

Basic Sql Commands⏹️

--SQL Script for Data Retrieval
SELECT column1, column2
FROM table_name
WHERE condition;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Data Manipulation
INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

UPDATE table_name
SET column1 = new_value
WHERE condition;

DELETE FROM table_name
WHERE condition;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Table Management
CREATE TABLE table_name (
    column1 datatype,
    column2 datatype
);

ALTER TABLE table_name
ADD column_name datatype;

DROP TABLE table_name;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Database Management
CREATE DATABASE database_name;

USE database_name;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Indexing
CREATE INDEX index_name
ON table_name (column1, column2);

DROP INDEX index_name
ON table_name;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Transaction Control
BEGIN TRANSACTION;
Enter fullscreen mode Exit fullscreen mode
-- SQL statements within the transaction
COMMIT;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Views
CREATE VIEW view_name AS
SELECT column1, column2
FROM table_name
WHERE condition;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Constraints
ALTER TABLE table_name
ADD CONSTRAINT constraint_name
CHECK (condition);
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for Functions
SELECT COUNT(column) AS count
FROM table_name;
Enter fullscreen mode Exit fullscreen mode
-- SQL Script for User Management
CREATE USER username IDENTIFIED BY 'password';
Enter fullscreen mode Exit fullscreen mode

Top comments (0)