Database SQL
SQL Database
1. How can we create a table in SQL
"Employee" table:
1. CREATE TABLE Employee: This is the beginning of the SQL statement. It instructs the database to create a new table named "Employee."
2. (EmpId smallint IDENTITY(1, 1) PRIMARY KEY: This part defines the first column of the "Employee" table.
EmpId:** This is the name of the column, representing the employee's identification number.
smallint:** This is the data type of the column. It's used for small whole numbers.
IDENTITY(1, 1):** The "IDENTITY" property is applied to this column, which means it will automatically generate unique values. The two numbers in parentheses indicate that the values will start at 1 and increment by 1 for each new record.
PRIMARY KEY: This constraint is added to the column to ensure that each value in this column is unique, serving as a unique identifier for each employee record.
3. EmpName VARCHAR(50):** This line defines the second column of the "Employee" table.
EmpName: This is the column name, storing the employee's name.
VARCHAR(50): This specifies the data type for the column. VARCHAR is used for variable-length character strings, and it can store up to 50 characters.
4.EmpAddress VARCHAR(50): Similar to the previous line, this defines the third column for the employee's address.
5. EmpAge INT: This line defines the fourth column for the employee's age.
EmpAge: Column name for storing the employee's age.
INT: INT stands for "integer," and it is used to store whole numbers.
6. EmpSalary INT: Similar to the previous line, this defines the fifth column for the employee's salary.
7.DateOfBirth DATE:This is the final line, defining the sixth column for the employee's date of birth.
DateOfBirth: The column name for storing the employee's date of birth.
DATE: This data type is used to store date values.
Once this SQL code is executed, it will create a table named "Employee" with the specified columns and their properties. The "EmpId" column will automatically generate unique values for each new record, and it is marked as the primary key to ensure data integrity.
This table can be used to store information about employees, including their names, addresses, ages, salaries, and dates of birth, in a structured and organized manner within a database.
Program: 1:
How to show the table in SQL:
SELECT * FROM Employee;
How to insert the value into the table:
Program: 2:
Comments
Post a Comment