Emp_I
d 1 2
3
Emp_Id
1
Employee Table
Employee Table
Emp_Name
Sakshi
Sourav
Pragati
Emp_Name
Sakshi
Address
Delhi
Address
Delhi
Hazaribagh
Nanded
Mobile_No
12345678
9
22336579
6
175468965
Mobile_No
123456789
The result set will have columns named fname and lname instead of first_name and last_name, respectively.
Email
[email protected]
Email
[email protected]
[email protected]
[email protected]
This statement will rename the column old_column_name to new_column_name in the table my_table and change its data type to
VARCHAR(50).
Giving an alias to a column means giving it a temporary name using the AS keyword while executing an SQL query. It does not affect the
original column name in the table schema. Aliases are used for readability or to resolve naming conflicts in query results.
In the above table, Emp_Id is the primary key. Each employee has a unique ID assigned to them, ensuring that no two employees share the
same ID.
A primary key is a set of one or more fields/columns of a table that uniquely identifies a record in a database table. It can not accept null, or
duplicate values. It is either an existing table column or a column that is specifically generated by the database according to a defined
sequence.
A unique key is a unique value amongst other values that are used to protect duplication of the values in a column of the table. The primary use
of a unique key in a table is to prevent duplicate values. But, when it comes to the unique values, the primary key also includes them. So, there
is one big difference that makes a unique key different, and it is that the unique key may have a NULL as a value but the primary key does not
allow NULL as a value.
Example of Unique Key
Example of Primary Key
Syntax to Give an Alias to a Column
Example of Give an Alias to a Column
30. What is a primary key?
31. What is a Unique Key? Elaborate with an example.
SELECT column_name AS alias_name
FROM table_name;
SELECT first_name AS fname, last_name AS lname
FROM employees;