SQL Questions III Flashcards
What is the difference between CHAR and VARCHAR2 datatype in SQL?
Both of these data types are used for characters, but varchar2 is used for character strings of variable length, whereas char is used for character strings of fixed length. For example, if we specify the type as char(5) then we will not be allowed to store a string of any other length in this variable, but if we specify the type of this variable as varchar2(5) then we will be allowed to store strings of variable length. We can store a string of length 3 or 4 or 2 in this variable.
What do you mean by data definition language?
Data definition language or DDL allows to execution of queries like CREATE, DROP, and ALTER. That is those queries that define the data.
What do you mean by data manipulation language?
Data manipulation Language or DML is used to access or manipulate data in the database. It allows us to perform the below-listed functions:
Insert data or rows in a database
Delete data from the database
Retrieve or fetch data
Update data in a database.
What is the view in SQL?
Views in SQL are a kind of virtual table. A view also has rows and columns as they are on a real table in the database. We can create a view by selecting fields from one or more tables present in the database. A View can either have all the rows of a table or specific rows based on certain conditions.
The CREATE VIEW statement of SQL is used for creating views.
CREATE VIEW view_name AS
SELECT column1, column2…..
FROM table_name
WHERE condition;
view_name: Name for the View
table_name: Name of the table
condition: Condition to select rows
What do you mean by foreign key?
A Foreign key is a field that can uniquely identify each row in another table. And this constraint is used to specify a field as a Foreign key. That is this field points to the primary key of another table. This usually creates a kind of link between the two tables.
What are table and Field?
Table: A table has a combination of rows and columns. Rows are called records and columns are called fields. In MS SQL Server, the tables are being designated within the database and schema names.
Field: In DBMS, a database field can be defined as – a single piece of information from a record.
What is the primary key?
A Primary Key is one of the candidate keys. One of the candidate keys is selected as the most important and becomes the primary key. There cannot be more than one primary key in a table
What is a Default constraint?
The DEFAULT constraint is used to fill a column with default and fixed values. The value will be added to all new records when no other value is provided.
What is normalization?
It is a process of analyzing the given relation schemas based on their functional dependencies and primary keys to achieve the following desirable properties:
Minimizing Redundancy
Minimizing the Insertion, Deletion, And Update Anomalies
Relation schemas that do not meet the properties are decomposed into smaller relation schemas that could meet desirable properties.
What is Denormalization?
Denormalization is a database optimization technique in which we add redundant data to one or more tables.
This can help us avoid costly joins in a relational database. Note that denormalization does not mean not doing normalization.
It is an optimization technique that is applied after normalization.
In a traditional normalized database, we store data in separate logical tables and attempt to minimize redundant data. We may strive to have only one copy of each piece of data in the database.
What is a query?
An SQL query is used to retrieve the required data from the database. However, there may be multiple SQL queries that yield the same results but with different levels of efficiency. An inefficient query can drain the database resources, reduce the database speed or result in a loss of service for other users. So it is very important to optimize the query to obtain the best database performance.
What is a subquery?
In SQL, a Subquery can be simply defined as a query within another query. In other words, we can say that a Subquery is a query that is embedded in the WHERE clause of another SQL query.
What are the different operators available in SQL
There are three operators available in SQL namely:
Arithmetic Operators
Logical Operators
Comparison Operators
What is a Constraint?
Constraints are the rules that we can apply to the type of data in a table. That is, we can specify the limit on the type of data that can be stored in a particular column in a table using constraints. For more details please refer to SQL|Constraints article.