The document provides an overview of SQL codes used in Microsoft Access for creating, modifying, and querying database objects. It includes syntax and examples for commands such as CREATE TABLE, ALTER TABLE, INSERT INTO, SELECT, and JOIN. The summary highlights essential SQL operations for database design and management.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views4 pages
SQL Notes
The document provides an overview of SQL codes used in Microsoft Access for creating, modifying, and querying database objects. It includes syntax and examples for commands such as CREATE TABLE, ALTER TABLE, INSERT INTO, SELECT, and JOIN. The summary highlights essential SQL operations for database design and management.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4
Here is an overview of the SQL codes used in designing a
database using Microsoft Access:
SQL Codes for Creating Database Objects CREATE TABLE • Used to create a new table in the database. • • Syntax: CREATE TABLE table_name (column1 data_type, column2 data_type, ...); • • Example: CREATE TABLE Employees (EmployeeID AUTOINCREMENT, FirstName TEXT, LastName TEXT, Email TEXT); • CREATE INDEX • Used to create an index on a specific column or set of columns in a table. • • Syntax: CREATE INDEX index_name ON table_name (column1, column2, ...); • • Example: CREATE INDEX idx_EmployeeID ON Employees (EmployeeID); • CREATE RELATIONSHIP • Used to establish relationships between tables. • • Syntax: Not directly supported in Access SQL, but can be achieved through the Relationships window or by using the ALTER TABLE statement with the ADD CONSTRAINT clause. • SQL Codes for Modifying Database Objects ALTER TABLE • Used to modify the structure of an existing table. • • Syntax: ALTER TABLE table_name ADD/MODIFY/DROP column_name data_type; • • Example: ALTER TABLE Employees ADD Phone TEXT; • DROP TABLE • Used to delete an existing table from the database. • • Syntax: DROP TABLE table_name; • • Example: DROP TABLE Employees; • DROP INDEX • Used to delete an existing index from a table. • • Syntax: DROP INDEX index_name ON table_name; • • Example: DROP INDEX idx_EmployeeID ON Employees; • SQL Codes for Data Manipulation INSERT INTO • Used to add new records to a table. • • Syntax: INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...); • • Example: INSERT INTO Employees (FirstName, LastName, Email) VALUES ('John', 'Doe', '[email protected]'); • UPDATE • Used to modify existing records in a table. • • Syntax: UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition; • • Example: UPDATE Employees SET Email = '[email protected]' WHERE EmployeeID = 1; • DELETE • Used to delete existing records from a table. • • Syntax: DELETE FROM table_name WHERE condition; • • Example: DELETE FROM Employees WHERE EmployeeID = 1; • SQL Codes for Querying Data SELECT • Used to retrieve data from one or more tables. • • Syntax: SELECT column1, column2, ... FROM table_name WHERE condition; • • Example: SELECT FirstName, LastName FROM Employees WHERE Department = 'Sales'; • JOIN • Used to combine data from two or more tables based on a common column. • • Syntax: SELECT column1, column2, ... FROM table1 INNER/LEFT/RIGHT JOIN table2 ON table1.column = table2.column; • • Example: SELECT Employees.FirstName, Employees.LastName, Orders.OrderDate FROM Employees INNER JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID; • GROUP BY • Used to group data by one or more columns and perform aggregate functions. • • Syntax: SELECT column1, column2, ... FROM table_name GROUP BY column1, column2, ...; • • Example: SELECT Department, AVG(Salary) FROM Employees GROUP BY Department; • HAVING • Used to filter grouped data based on a condition. • • Syntax: SELECT column1, column2, ... FROM table_name GROUP BY column1, column2, ... HAVING condition; • • Example: SELECT Department, AVG(Salary) FROM Employees GROUP BY Department HAVING AVG(Salary) > 50000; • These are the basic SQL codes used in designing and querying a database in Microsoft Access.