-
-
Notifications
You must be signed in to change notification settings - Fork 2
DROP TABLE
Oxford Harrison edited this page Nov 11, 2024
·
16 revisions
docs ➞ ddl ➞ drop ➞ drop table
See also ➞ ALTER DATABASE ➞
Manage Tables
Drop table:
// (a): SQL syntax
const savepoint = await client.query(
`DROP TABLE database_1.table_1`,
{ desc: 'Drop description' }
);
// (b): Function-based syntax
const savepoint = 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 IF EXISTS
check:
// (a): SQL syntax
const savepoint = await client.query(
`DROP TABLE IF EXISTS database_1.table_1`,
{ desc: 'Drop description' }
);
// (b): Function-based syntax
const savepoint = await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description', ifExists: true }
);
Drop with a CASCADE
or RESTRICT
rule (PostgreSQL):
// (a): SQL syntax
const savepoint = await client.query(
`DROP TABLE database_1.table_1 CASCADE`,
{ desc: 'Drop description' }
);
// (b): Function-based syntax
const savepoint = await client.database('database_1').dropTable(
'table_1',
{ desc: 'Drop description', cascade: true }
);