Toon posts:

Leegmaken tabellen in MSSQL database

Pagina: 1
Acties:
  • 202 views sinds 30-01-2008

Verwijderd

Topicstarter
Hoe kun je in één keer (of via een script of php) alle tabellen in MSSQL database leegmaken (dus alle records er uit, structuur blijft bestaan)? :o

  • gorgi_19
  • Registratie: Mei 2002
  • Laatst online: 13:24

gorgi_19

Kruimeltjes zijn weer op :9

Truncate
Zie hiervoor books online

[sociale modus]
TRUNCATE TABLE
Removes all rows from a table without logging the individual row deletes.

Syntax
TRUNCATE TABLE name

Arguments
name

Is the name of the table to truncate or from which all rows are removed.

Remarks
TRUNCATE TABLE is functionally identical to DELETE statement with no WHERE clause: both remove all rows in the table. But TRUNCATE TABLE is faster and uses fewer system and transaction log resources than DELETE.

The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table's data, and only the page deallocations are recorded in the transaction log.

TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes and so on remain. The counter used by an identity for new rows is reset to the seed for the column. If you want to retain the identity counter, use DELETE instead. If you want to remove table definition and its data, use the DROP TABLE statement.

You cannot use TRUNCATE TABLE on a table referenced by a FOREIGN KEY constraint; instead, use DELETE statement without a WHERE clause. Because TRUNCATE TABLE is not logged, it cannot activate a trigger.

TRUNCATE TABLE may not be used on tables participating in an indexed view.

Examples
This example removes all data from the authors table.

TRUNCATE TABLE authors
[/sociale modus]

[ Voor 101% gewijzigd door gorgi_19 op 24-01-2003 15:26 ]

Digitaal onderwijsmateriaal, leermateriaal voor hbo


Verwijderd

installeer myadmin daar kan het heel gemakkelijk mee

  • D2k
  • Registratie: Januari 2001
  • Laatst online: 09-01 11:25

D2k

manual werk dus :)

Doet iets met Cloud (MS/IBM)


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 09-01 11:25

D2k

niet zo manual werk :)
ff heropend
uit zijn mail
Ik had het P&W Topic: Leegmaken tabellen in MSSQL database opgesteld.
Ik kreeg daar snel drie racties op en daarna sloot jij de topic met verwijzing naar de manual.

Helaas hebben de antwoorden geen betrekking op de vraag om ALLE tabellen in de database in een keer leeg te maken. Dus niet één voor één.
Ik heb een database met honderden tabellen en die maak je dus niet één voor één leeg met TRUNCATE.
Ook de manual geeft hier geen oplossing voor.

Een mogelijkheid zou kunnen zijn om een script toe te passen als:
truncate (show tabels) (iets wat waarschijnlijk in MySQL wel kan, daar geeft 'show tabels' een tabel terug die de namen bevat van de tabellen in de database ). Maar de show syntax bestaat niet in MSSQL.

Doet iets met Cloud (MS/IBM)


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 09-01 11:25

D2k

foei

Doet iets met Cloud (MS/IBM)

Pagina: 1

Dit topic is gesloten.