SQL_1
SQL_1
In SQL, data types define the kind of data that can be stored in a column or variable.
SQL
• CHAR is for fixed length & VARCHAR is for variable length strings.
Generally,
• VARCHAR is better as it only occupies necessary memory & works
more efficiently.
• We can also use UNSIGNED with datatypes when we only have
positive values to add.
• Eg - UNSIGNED INT
Types of SQL Commands:
DQL (Data Query Language) :
1.Used to retrieve data from databases. (SELECT)
2. DDL (Data Definition Language) : Used to create, alter, and delete database
objects like tables, indexes, etc. (CREATE, DROP, ALTER, RENAME,
TRUNCATE)
3. DML (Data Manipulation Language): Used to modify the database. (INSERT,
UPDATE, DELETE)
4. DCL (Data Control Language): Used to grant & revoke permissions. (GRANT,
REVOKE)
5. TCL (Transaction Control Language): Used to manage transactions. (COMMIT,
ROLLBACK, START TRANSACTIONS, SAVEPOINT)
Data Definition Language (DDL)
• Data Definition Language (DDL) is a subset of SQL (Structured Query
Language) responsible for defining and managing the structure of
databases and their objects.
• DDL commands enable you to create, modify, and delete database
objects like tables, indexes, constraints, and more.
• Key DDL Commands are:
Key DDL Commands are:
• ● CREATE TABLE:
• ○ Used to create a new table in the database.
• ○ Specifies the table name, column names, data types, constraints,
and more.
• ○ Example: CREATE TABLE employees (id INT PRIMARY KEY, name
VARCHAR(50), salary DECIMAL(10, 2));
• ALTER TABLE:
• ○ Used to modify the structure of an existing table.
• ○ You can add, modify, or drop columns, constraints, and more.
• ○ Example: ALTER TABLE employees ADD COLUMN email
VARCHAR(100);
DROP TABLE:
○ Used to delete an existing table along with its data and structure.
○ Example: DROP TABLE employees;