Basic syntax Flashcards
what is select for?
The SELECT statement in SQL is used to retrieve or fetch data from a database table. It allows you to query the database and retrieve specific columns or all columns from one or more tables. The data returned by the SELECT statement is stored in a result table, also known as a result set.
what is fetch?
Fetch refers to the retrieval of data by a software program, script, or hardware device. It is the process of obtaining data from a source and moving it to another location or displaying it on a screen.
In SQL, the SELECT statement is used to fetch data from a database table.
what is insert into for?
The INSERT INTO statement is used to insert new rows of data in a table
INSERT INTO table_name (column1, column2, column3)
VALUES (value1, value2, value3);
what is the UPDATE statement for?
The UPDATE statement is used to modify existing records in a table. It is a part of Data Manipulation Language (DML), which only modifies the data present in a table without affecting the table’s structure.
UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;
What is the difference between the UPDATE statement and the INSERT statement in SQL?
UPDATE statement:
+Modifies the existing records in a table.
+Changes the values of one or more columns in one or more rows.
+Uses the WHERE clause to specify which rows to update.
+Does not affect the table’s structure.
INSERT statement:
+Adds new records to a table.
+Inserts one or more rows into a table.
+Does not require a WHERE clause.
+Does not modify existing records.
what is the The DELETE statement for?
The DELETE statement in SQL is used to remove existing records from a table. It allows you to delete one or more rows from a table based on specified conditions.
DELETE FROM table_name WHERE condition;
what is The CREATE TABLE statement for?
The CREATE TABLE statement is used to create a new table in a database
CREATE TABLE table_name (
column1 datatype
constraints,
column2 datatype
constraints,
column3 datatype
constraints
);
what is The ALTER TABLE statement for?
The ALTER TABLE statement in SQL is used to modify the structure of an existing table. It allows you to add, modify, or delete columns in a table, as well as add or remove various constraints on existing tables.
– To add a column
ALTER TABLE table_name
ADD column_name datatype;
– To delete/drop column
ALTER TABLE table_name
DROP COLUMN column_name;
– To modify existing column
ALTER TABLE table_name
MODIFY COLUMN
column_name datatype;
what are constrains?
Constraints in SQL are rules that are applied to the data in a table. They are used to limit the type of data that can be stored in a particular column in a table. Constraints help to maintain the accuracy, integrity, and reliability of a table’s data. They can be created at a column or table level. If you declare constraints at the column level, they will apply to a single column. On the other hand, if you declare them at the table level, they will apply to more than one column.
what is the The DROP TABLE statement for?
The DROP statement in SQL is used to delete or remove entities such as databases, tables, columns, indexes, constraints, etc. When an entity is dropped, all its related information (data and metadata) will be deleted.
DROP command:
+The DROP command is a Data Definition Language (DDL) command.
+It is used to remove entities such as databases, tables, columns, indexes, constraints, etc.
+When an entity is dropped, all its related information (data and metadata) will be deleted.
+For example, dropping a table will delete the table itself, along with its data, indexes, constraints, and triggers.
+The DROP command is irreversible and permanently removes the entity from the database.
+Syntax: DROP entity_type entity_name;
DELETE command:
+The DELETE command is a Data Manipulation Language (DML) command.
+It is used to remove specific rows or records from a table based on specified conditions.
+The DELETE command is used to selectively remove data from a table, while keeping the table structure intact.
+It can be used with the WHERE clause to specify the conditions for deleting specific rows.
+The DELETE command is reversible, as it can be rolled back if executed within a transaction.
+Syntax: DELETE FROM table_name WHERE condition;