-
-
Notifications
You must be signed in to change notification settings - Fork 2
DROP TABLE
Oxford Harrison edited this page Nov 15, 2024
·
16 revisions
See APIS ➞
client.query(),database.dropTable()
See related ➞ ALTER DATABASE ➞
Manage Tables
Drop table:
// (a): SQL syntax
await client.query(
`DROP TABLE database_1.table_1`,
{ desc: 'Drop description' }
);// (b): Function-based syntax
await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description' }
);Note
While the default function-based syntax may read "drop table", you can imply the "view" kind by setting options.kind === 'view':
client.dropTable(..., { desc: 'Drop description', kind: 'view' });Drop with an EXISTS check:
// (a): SQL syntax
await client.query(
`DROP TABLE IF EXISTS database_1.table_1`,
{ desc: 'Drop description' }
);// (b): Function-based syntax
await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description', ifExists: true }
);Drop with a CASCADE or RESTRICT rule (PostgreSQL):
// (a): SQL syntax
await client.query(
`DROP TABLE database_1.table_1 CASCADE`,
{ desc: 'Drop description' }
);// (b): Function-based syntax
await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description', cascade: true }
);Return the dropped table schema:
// (a): SQL syntax
const schema = await client.query(
`DROP TABLE database_1.table_1
RETURNING SCHEMA`,
{ desc: 'Drop description' }
);// (b): Function-based syntax
const schema = await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description', returning: 'schema' }
);See related ➞
table.schema()
Return the associated savepoint instance:
// (a): SQL syntax
const savepoint = await client.query(
`DROP TABLE database_1.table_1
RETURNING SAVEPOINT`,
{ desc: 'Drop description' }
);// (b): Function-based syntax
const savepoint = await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description', returning: 'savepoint' }
);See related ➞
database.savepoint()