Dbms SQL Queries
Dbms SQL Queries
INSERT INTO Employees (EmpID, FirstName, LastName) VALUES (1, 'John', 'Doe');
UPDATE: Modifies existing records in a table.
ROLLBACK;
SAVEPOINT: Sets a point within a transaction to which you can later roll back.
SAVEPOINT SavePoint1;
Summary
DDL (Data Definition Language): Deals with the structure of the database (e.g.,
CREATE, ALTER, DROP).
DML (Data Manipulation Language): Deals with the manipulation of data within
database objects (e.g., INSERT, UPDATE, DELETE, SELECT).
DCL (Data Control Language): Deals with the permissions and access controls (e.g.,
GRANT, REVOKE).
TCL (Transaction Control Language): Deals with transaction management (e.g.,
COMMIT, ROLLBACK, SAVEPOINT).
The DepartmentID in the Employees table must match an existing DepartmentID in the
Departments table.
If you try to insert a record into Employees with a DepartmentID that does not
exist in the Departments table,
SQL Server will prevent the insertion.
Cascading Actions:
-- Insert department
INSERT INTO Departments (DepartmentID, DepartmentName) VALUES
(1, 'HR'),
(2, 'IT');
-- Error: The INSERT statement conflicted with the FOREIGN KEY constraint
-- "FK_Employees_Departments". The conflict occurred in database "yourDB",
-- table "Departments", column 'DepartmentID'.
After this, all employees linked to the IT department in the Employees table will
also be automatically deleted.
This removes the foreign key constraint, effectively dropping the cascading
behavior.
This query will return the name of the foreign key constraint, which you can use in
the DROP CONSTRAINT statement.
Explanation:
LIKE '%[^a-zA-Z]%' ensures that only letters (uppercase and lowercase) are allowed
in the FirstName column.
LEN(FirstName) > 0 ensures that the FirstName column is not empty.