From cf0f90596c879815d096a8b3b3c83198c6485e08 Mon Sep 17 00:00:00 2001 From: Imran Imtiaz Date: Fri, 1 Nov 2024 16:27:38 +0400 Subject: [PATCH] Update SQL Basics Create Table and Insert Into I combined both table creation queries and the data insertion queries into one unified script, which includes: 1. **Table Creation Statements**: - `EmployeeDemographics` table with primary key, `NOT NULL` constraints, and checks for valid age and gender values. - `EmployeeSalary` table with a primary key, `NOT NULL` constraints, a `CHECK` constraint for valid salary, and a foreign key relationship linking `EmployeeID` to `EmployeeDemographics`. 2. **Data Insertion Statements**: - Insert statements for both tables with values provided in a clean and formatted way. This makes it convenient to run everything at once, creating the tables and populating them with data. --- SQL Basics Create Table and Insert Into | 76 ++++++++++++------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/SQL Basics Create Table and Insert Into b/SQL Basics Create Table and Insert Into index 6a236ef..7fd8380 100644 --- a/SQL Basics Create Table and Insert Into +++ b/SQL Basics Create Table and Insert Into @@ -1,42 +1,40 @@ +-- Create Table: EmployeeDemographics +CREATE TABLE EmployeeDemographics ( + EmployeeID INT PRIMARY KEY, + FirstName VARCHAR(50) NOT NULL, + LastName VARCHAR(50) NOT NULL, + Age INT CHECK (Age > 0), + Gender VARCHAR(50) CHECK (Gender IN ('Male', 'Female')) +); -Table 1 Query: -Create Table EmployeeDemographics -(EmployeeID int, -FirstName varchar(50), -LastName varchar(50), -Age int, -Gender varchar(50) -) +-- Create Table: EmployeeSalary +CREATE TABLE EmployeeSalary ( + EmployeeID INT PRIMARY KEY, + JobTitle VARCHAR(50) NOT NULL, + Salary INT CHECK (Salary > 0), + FOREIGN KEY (EmployeeID) REFERENCES EmployeeDemographics(EmployeeID) +); -Table 2 Query: -Create Table EmployeeSalary -(EmployeeID int, -JobTitle varchar(50), -Salary int -) +-- Insert Data into EmployeeDemographics +INSERT INTO EmployeeDemographics (EmployeeID, FirstName, LastName, Age, Gender) VALUES + (1001, 'Jim', 'Halpert', 30, 'Male'), + (1002, 'Pam', 'Beasley', 30, 'Female'), + (1003, 'Dwight', 'Schrute', 29, 'Male'), + (1004, 'Angela', 'Martin', 31, 'Female'), + (1005, 'Toby', 'Flenderson', 32, 'Male'), + (1006, 'Michael', 'Scott', 35, 'Male'), + (1007, 'Meredith', 'Palmer', 32, 'Female'), + (1008, 'Stanley', 'Hudson', 38, 'Male'), + (1009, 'Kevin', 'Malone', 31, 'Male'); - - -Table 1 Insert: -Insert into EmployeeDemographics VALUES -(1001, 'Jim', 'Halpert', 30, 'Male'), -(1002, 'Pam', 'Beasley', 30, 'Female'), -(1003, 'Dwight', 'Schrute', 29, 'Male'), -(1004, 'Angela', 'Martin', 31, 'Female'), -(1005, 'Toby', 'Flenderson', 32, 'Male'), -(1006, 'Michael', 'Scott', 35, 'Male'), -(1007, 'Meredith', 'Palmer', 32, 'Female'), -(1008, 'Stanley', 'Hudson', 38, 'Male'), -(1009, 'Kevin', 'Malone', 31, 'Male') - -Table 2 Insert: -Insert Into EmployeeSalary VALUES -(1001, 'Salesman', 45000), -(1002, 'Receptionist', 36000), -(1003, 'Salesman', 63000), -(1004, 'Accountant', 47000), -(1005, 'HR', 50000), -(1006, 'Regional Manager', 65000), -(1007, 'Supplier Relations', 41000), -(1008, 'Salesman', 48000), -(1009, 'Accountant', 42000) +-- Insert Data into EmployeeSalary +INSERT INTO EmployeeSalary (EmployeeID, JobTitle, Salary) VALUES + (1001, 'Salesman', 45000), + (1002, 'Receptionist', 36000), + (1003, 'Salesman', 63000), + (1004, 'Accountant', 47000), + (1005, 'HR', 50000), + (1006, 'Regional Manager', 65000), + (1007, 'Supplier Relations', 41000), + (1008, 'Salesman', 48000), + (1009, 'Accountant', 42000);