In this article let us see how can we check for the validation of mails in the student database using MSSQL as the database server. For example, if the email is like abcdedfABCDEF…email@example.com this is the valid form of an email if it is other than this then that is said to Invalid. So, now we will discuss this concept in detail step-by-step:
Step 1: Creating a database college by using the following SQL query as follows.
CREATE DATABASE college;
Step 2: Using the database student using the following SQL query as follows.
Step 3: Creating a table student with 4 columns using the following SQL query as follows.
CREATE TABLE student
Step 4: To view the description of the table in the database using the following SQL query as follows.
EXEC sp_columns student;
Step 5: Inserting rows into student_details table using the following SQL query as follows.
INSERT INTO student VALUES
Step 6: Viewing the table student_details after inserting rows by using the following SQL query as follows.
SELECT * FROM student;
Query: Now we are querying to display all the student details with valid emails. So, the email validation is done by using pattern matching which can be done by using LIKE operator in MSSQL. It checks for the fixed pattern set by the database designer in the data and displays the data that matches the fixed pattern.
SELECT * FROM table_name
WHERE attribute LIKE 'pattern';
SELECT * FROM student
WHERE s_email LIKE '%@gmail.com';
Only the students with valid emails are displayed in the tables.