Writing SQL Flashcards
1
Q
CREATE A TABLE
A
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
Email VARCHAR(100)
);
2
Q
CREATE A STORED PROCEDURE
A
CREATE PROCEDURE GetCustomerByID
@CustomerID INT
AS
BEGIN
SELECT * FROM Customers WHERE CustomerID = @CustomerID;
END;
3
Q
TRY / CATCH
A
BEGIN TRY
– Code block where errors might occur
– …
END TRY
BEGIN CATCH
– Error handling logic
– …
END CATCH;
4
Q
ROLLBACK
A
BEGIN TRANSACTION;
– SQL statements within the transaction
– …
IF <some>
ROLLBACK;</some>
COMMIT;