SQL queries
SQL queries
FROM table_name;
3. SELECT column1, column2, ... FROM table_name WHERE condition;
4. UPDATE table_name SET column1 = value1, column2 = value2, ...
WHERE condition;
5. DELETE FROM table_name WHERE condition;
6. DROP DATABASE databasename;
7. CREATE TABLE table_name ( column1 datatype, column2
datatype,....);
8. DROP TABLE table_name;
9. ALTER TABLE table_name ADD column_name datatype;
10. CREATE TABLE Persons ( ID int NOT NULL,
LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int, PRIMARY KEY (ID) );
11. CREATE TABLE Persons ( ID int NOT NULL,
LastName varchar(255) NOT NULL, FirstName
varchar(255) NOT NULL,
Age int);
12. ALTER TABLE Persons ALTER COLUMN Age int NOT NULL;
13. CREATE TABLE Persons ( ID int NOT NULL UNIQUE,
LastName varchar(255) NOT NULL, FirstName varchar(255),
Age int );
The FOREIGN KEY constraint is used to prevent actions that would destroy links
between tables.
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to
the PRIMARY KEY in another table.
The table with the foreign key is called the child table, and the table with the
primary key is called the referenced or parent table.
Notice that the "PersonID" column in the "Orders" table points to the "PersonID"
column in the "Persons" table.
The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons"
table.
The "PersonID" column in the "Orders" table is a FOREIGN KEY in the "Orders"
table.
The FOREIGN KEY constraint prevents invalid data from being inserted into the
foreign key column, because it has to be one of the values contained in the
parent table.