sqlcmd.net validated sql reference

#ddl

Commands grouped around the same concept, pattern, or recurring problem.

19 commands with this tag Browse related patterns quickly
beginner defining MySQL MariaDB SQL Server PostgreSQL SQLite

Add A Column To An Existing Table

Extend a table's structure by adding a new column with `ALTER TABLE`.

intermediate ddl MySQL MariaDB SQL Server PostgreSQL SQLite

Add a Foreign Key Constraint

Enforce referential integrity by linking a column to the primary key of another table so orphaned rows cannot be inserted.

intermediate ddl MySQL MariaDB SQL Server PostgreSQL

Change a Column's Data Type With ALTER TABLE

Modify the data type, default value, or nullability of an existing column without recreating the table.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Create A Reusable Query With CREATE VIEW

Save a `SELECT` statement as a named view so it can be queried like a table.

beginner defining MySQL MariaDB SQL Server PostgreSQL SQLite

Create A Table

Define a new table with column names and data types using `CREATE TABLE`.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Create a Table From a Query Result

Materialize a query's output as a new table in one step using `CREATE TABLE AS SELECT` or `SELECT INTO`.

intermediate ddl MySQL MariaDB SQL Server PostgreSQL SQLite

Create a Temporary Table

Build a table that exists only for the current session and is discarded automatically when the connection closes.

beginner defining MySQL MariaDB SQL Server PostgreSQL SQLite

Delete A Table

Permanently remove a table and all its data with `DROP TABLE`.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Enforce Uniqueness With CREATE UNIQUE INDEX

Create a unique index so the database rejects duplicate values in one or more columns.

beginner inserting MySQL MariaDB SQL Server PostgreSQL SQLite

Fill Omitted Columns With DEFAULT

Define a column default so inserts can omit routine values and still store a complete row.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Generate Row IDs Automatically

Define an identity or auto-increment column so new rows receive numeric IDs without the insert supplying them.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Remove A Column From A Table With ALTER TABLE DROP COLUMN

Permanently delete a column and all its data from a table using ALTER TABLE.

intermediate deleting MySQL MariaDB SQL Server PostgreSQL SQLite

Remove All Rows From A Table With TRUNCATE

Delete every row in a table quickly with TRUNCATE TABLE, which is faster than DELETE with no WHERE clause.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Remove an Index With DROP INDEX

Drop an index that is no longer useful so writes no longer have to maintain it.

beginner ddl MySQL MariaDB SQL Server PostgreSQL SQLite

Rename a Column With ALTER TABLE

Change a column's name in place without dropping or recreating the table or its data.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Rename a Table

Change a table name while keeping its existing rows and columns.

advanced defining MySQL MariaDB SQL Server PostgreSQL SQLite

Speed Up Queries With CREATE INDEX

Create an index on one or more columns to make lookups and joins faster.

intermediate schema MySQL MariaDB SQL Server PostgreSQL SQLite

Store a Computed Value Automatically With Generated Columns

Define a column whose value is always derived from an expression over other columns — the database recomputes or stores it on every write so queries never need to repeat the formula.

intermediate defining MySQL MariaDB SQL Server PostgreSQL SQLite

Validate Column Values With CHECK

Use a `CHECK` constraint to reject rows whose values fall outside an allowed rule.