You are on page 1of 3

Assignment-1

Q1. Install MS SQL Server: -


Ans- Already installed on my pc .

Q2. Difference between char and varchar data type:-


Ans-

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.

2. It uses static memory location. 2.It uses dynamic memory location.

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.

Q.3. Explain the types of SQL Commands.


Ans - Based on functionalities , there are five types of SQL Commands:-

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.

Syntax:- CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);


Example:-
CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email VARCHAR2(100), DOB DATE);
2. DML(Data Manipulation Language):- Once the tables are created and the database is generated
using DDL commands, DML commands are used for manipulation inside those tables and
databases .
The command of DML is not auto-committed, which means it can't permanently save all the
changes in the database. They can be rollback.
some commands that come under DML: - 1.) INSERT . 2) UPDATE 3)DELETE
Example:- syntax: INSERT INTO TABLE_NAME VALUES (value1, value2, value3, .... valueN);

For example:

INSERT INTO TATAMCGRAW_PUB (Author, Subject) VALUES ("Sonoo", "DBMS");

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:

SELECT emp_name FROM employee WHERE age > 30

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.

some commands that come under DCL:


○ Grant
○ Revoke
a. Grant: It is used to give user access privileges to a database.

Example: -GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;


b . Revoke: It is used to take back permissions from the user.
Example: - REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1, USER2;

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;

Q4. Explain NVarchar and Nchar


Ans-
a) Varchar and NVarchar both are the data types which are used to declare data types of
variables.
b) Both Varchar and NVarchar are Variable length character data types.
c) Varchar stores Non-Unicode character and NVarchar stores Unicode character.
d) We can write only ASCII values in Varchar. Furthermore, ASCII values can only
represent 256 characters. such as Capital A-Z, Small a-z, numbers from 0–9.
where as in NVarchar we can write ASCII values and special characters . Unicode values can
represent more than 256 ASCII characters. Like Capital A-Z, Small a-z, numbers from 0–9 and
special characters like Chinese or Japanese characters.

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')

You might also like