0% found this document useful (0 votes)
15 views4 pages

SQL Command Syntax

The document outlines the SQL command syntax for various operations including CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, GRANT, and REVOKE. Each command is accompanied by its syntax and examples for better understanding. This serves as a quick reference guide for SQL commands and their usage.

Uploaded by

sanyalsingh2917
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

SQL Command Syntax

The document outlines the SQL command syntax for various operations including CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, GRANT, and REVOKE. Each command is accompanied by its syntax and examples for better understanding. This serves as a quick reference guide for SQL commands and their usage.

Uploaded by

sanyalsingh2917
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL Command Syntax

sql commands syntax create alter , drop , insert, update, delete , select , grant, revoke

Here’s the SQL syntax for each of the commands you mentioned:

1. CREATE (Create a Table)

sql

`CREATE TABLE table_name (


column1 datatype constraint,
column2 datatype constraint,
...
);
`

Example:

sql

`CREATE TABLE employees (


id INT PRIMARY KEY,
name VARCHAR(100),
salary DECIMAL(10,2)
);
`

2. ALTER (Modify a Table)

sql

`ALTER TABLE table_name


ADD column_name datatype; -- Add a new column

ALTER TABLE table_name


MODIFY column_name datatype; -- Modify a column

ALTER TABLE table_name


DROP COLUMN column_name; -- Remove a column
`

Example:

sql

`ALTER TABLE employees ADD age INT;


ALTER TABLE employees MODIFY salary DECIMAL(12,2);
ALTER TABLE employees DROP COLUMN age;
`

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/4
3. DROP (Delete a Table or Database)

sql

`DROP TABLE table_name; -- Delete a table


DROP DATABASE database_name; -- Delete a database
`

Example:

sql

`DROP TABLE employees;


DROP DATABASE company_db;
`

4. INSERT (Insert Data)

sql

`INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
`

Example:

sql

`INSERT INTO employees (id, name, salary) VALUES (1, 'John Doe', 50000);
`

5. UPDATE (Modify Existing Data)

sql

`UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
`

Example:

sql

`UPDATE employees SET salary = 60000 WHERE id = 1;


`

6. DELETE (Remove Data)

sql

`DELETE FROM table_name WHERE condition;

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/4
`

Example:

sql

`DELETE FROM employees WHERE id = 1;


`

(To delete all rows: `DELETE FROM employees;` but without a WHERE condition, this removes all records!)

7. SELECT (Retrieve Data)

sql

`SELECT column1, column2 FROM table_name WHERE condition;


SELECT * FROM table_name; -- Select all columns
`

Example:

sql

`SELECT name, salary FROM employees WHERE salary > 40000;


SELECT * FROM employees;
`

8. GRANT (Give Permissions)

sql

`GRANT privilege ON object TO user;


`

Example:

sql

`GRANT SELECT, INSERT ON employees TO user1;


`

9. REVOKE (Remove Permissions)

sql

`REVOKE privilege ON object FROM user;


`

Example:

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 3/4
sql

`REVOKE SELECT, INSERT ON employees FROM user1;


`

Let me know if you need more details! 🚀

Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/4

You might also like