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)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

CREATE A STORED PROCEDURE

A

CREATE PROCEDURE GetCustomerByID
@CustomerID INT
AS
BEGIN
SELECT * FROM Customers WHERE CustomerID = @CustomerID;
END;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

TRY / CATCH

A

BEGIN TRY
– Code block where errors might occur
– …
END TRY
BEGIN CATCH
– Error handling logic
– …
END CATCH;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ROLLBACK

A

BEGIN TRANSACTION;

– SQL statements within the transaction
– …

IF <some>
ROLLBACK;</some>

COMMIT;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly