0% found this document useful (0 votes)
8 views

SQL Commands in CMD

Uploaded by

26csvishu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SQL Commands in CMD

Uploaded by

26csvishu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL Commands in CMD with Examples

In this document, you'll find common SQL commands and examples for executing them in a

command-line

interface (CMD). Each command is provided with syntax and example usage, which is applicable to

most

SQL-based systems such as MySQL, PostgreSQL, and SQLite.

Database Commands
Create a Database

Syntax: CREATE DATABASE dbname;


Example: CREATE DATABASE school;
Explanation: This command creates a new database called 'school'.

Select a Database

Syntax: USE dbname;


Example: USE school;
Explanation: This command selects the 'school' database for use.

Delete a Database

Syntax: DROP DATABASE dbname;


Example: DROP DATABASE school;
Explanation: This command deletes the 'school' database.

Table Commands
Create a Table

Syntax: CREATE TABLE tablename (columns);


Example: CREATE TABLE students (id INT PRIMARY KEY, name VARCHAR(100), age INT, grade
CHAR(2));
Explanation: Creates a 'students' table with four columns.

Show Tables

Syntax: SHOW TABLES;


Example: SHOW TABLES;
Explanation: Lists all tables in the selected database.

Describe Table

Syntax: DESCRIBE tablename;


Example: DESCRIBE students;
Explanation: Displays the structure of the 'students' table.

Drop a Table

Syntax: DROP TABLE tablename;


Example: DROP TABLE students;
Explanation: Deletes the 'students' table.

Data Manipulation Commands


Insert Data

Syntax: INSERT INTO tablename (columns) VALUES (values);


Example: INSERT INTO students (id, name, age, grade) VALUES (1, 'John Doe', 18, 'A');
Explanation: Inserts a new student record into the 'students' table.

Select Data

Syntax: SELECT columns FROM tablename;


Example: SELECT name, age FROM students;
Explanation: Selects the 'name' and 'age' columns from the 'students' table.

Update Data

Syntax: UPDATE tablename SET column = value WHERE condition;


Example: UPDATE students SET age = 19 WHERE id = 1;
Explanation: Updates the 'age' of the student with id 1.

Delete Data

Syntax: DELETE FROM tablename WHERE condition;


Example: DELETE FROM students WHERE id = 1;
Explanation: Deletes the student with id 1 from the 'students' table.

You might also like