0% found this document useful (0 votes)
12 views

doc3

db2

Uploaded by

renu.dandge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

doc3

db2

Uploaded by

renu.dandge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

4.

Additional Commands for Practice


4.1 CREATE INDEX

You can create an index on a column to improve query performance.

Syntax:

sql
Copy code
CREATE INDEX index_name
ON table_name (column_name);

Example:

sql
Copy code
CREATE INDEX idx_lastname
ON Employees (LastName);

4.2 CONSTRAINTS in CREATE Table

 PRIMARY KEY: Ensures uniqueness of a column.


 FOREIGN KEY: Establishes a relationship between two tables.
 UNIQUE: Ensures all values in a column are different.
 CHECK: Ensures the data in a column satisfies a condition.

Example with Constraints:

sql
Copy code
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
Amount DECIMAL(10, 2),
CONSTRAINT FK_Customer FOREIGN KEY (CustomerID)
REFERENCES Customers(CustomerID),
CHECK (Amount > 0)
);

5. Common Errors to Watch For


 Syntax errors: Ensure that commands are structured correctly with proper commas
and parentheses.
 Constraint violations: Ensure you are inserting values that satisfy the constraints
defined in your schema.
 Data type mismatches: Ensure the data type of inserted values matches the column
definitions.
6. Further Learning Resources
 SQL Documentation: Most RDBMS (e.g., MySQL, PostgreSQL, SQL Server)
provide extensive documentation.
 SQL Practice Websites: Websites like LeetCode SQL Practice, HackerRank SQL,
and SQLZoo are great places to practice queries.
 Books: "SQL for Smarties" by Joe Celko, "Learning SQL" by Alan Beaulieu.

This manual provides you with a strong foundation in SQL’s DDL and DML commands.
Practicing these commands will help you better understand relational database design and
management.

You might also like