Professional Documents
Culture Documents
CHAR VARCHAR
1.Char is a data type in SQL that can store 1. Varchar is a datatype in SQL that holds
characters of a fixed length characters of variable length. This data type
stores character strings of up to 255 bytes in a
variable-length field.
3.Char data type can be used when we expect 3.Varchar data type can be used when we
the data values in a column to be of the same expect the data values in a column to be of
length. variable length.
4. Char takes 1 byte space for each character. 4. Varchar takes 1 byte for each character along
with some extra bytes to store length
information.
5.In CHAR, If the length of the string is less than 5.In VARCHAR, If the length of the string is less
set or fixed-length then it is padded with extra than the set or fixed-length then it will store as it
memory space is without being padded with extra memory
spaces.
1. DDL(Data Definition Language) :- DDL is used to change the structure of the table like creating a
table, deleting a table, altering a table, residing inside a database.
All the commands of DDL are auto-committed, which means it permanently saves all the
changes in the database.
For example : commands that come under DDL: CREATE, ALTER, DROP ,TRUNCATE
a .CREATE It is used to create a new table in the database.
For example:
3. DQL(Data Query Language): - DQL is used to fetch the data from the database
It uses only one command: SELECT
SELECT: This is the same as the projection operation of relational algebra. It is used to select
the attribute based on the condition described by WHERE clause.
Syntax:
1. SELECT expressions
2. FROM TABLES
3. WHERE conditions;
For example:
4.DCL(Data Control Language): DCL commands manage the matters and issues related to the data
controller in any database. DCL includes commands such as GRANT and REVOKE which mainly deal
with the rights, permissions, and other controls of the database system.
5. TCL(Transaction Control Language): TCL manages the issues and matters related to the
transactions in any database. They are used to roll back or commit the changes in the
database.
some commands that come under TCL:
○ COMMIT
○ ROLLBACK
○ SAVEPOINT
a. Commit: Commit command is used to save all the transactions to the database.
Syntax:
1. COMMIT;
Example: - DELETE FROM CUSTOMERS WHERE AGE = 25;
COMMIT;
Example : - a) Literals or values in varchar are enclosed within single inverted commas
INSERT INTO tableName VALUES ('Education')
b ) Literals or values in nvarchar are also enclosed within single inverted commas, but
they are prefixed with N. For example:
INSERT INTO tableName VALUES (N'Education')