Sunday, February 19, 2012

How can i TRUNCATE my table?

How can i TRUNCATE my table (removes rows that were produced at testing), so that in the actual running the automated IDNumber for my table start with 1.

you need to execute a sql state like:

TRUNCATE TABLE myTable;

http://msdn2.microsoft.com/en-us/library/ms177570.aspx

I usually do this through query analyzer.

|||

my table is called 'objects'. i can view my records/data under by right clicking on my Table ('Objects') in the 'Server Explorer'.

but don't know where to place this SQL code so that i could execute it, could you please advice?

and for my code would it be;

TRUNCATE TABLE ObjectsTable;

|||

right click the table and select: new query

put the truncate command in place of the select statement.

dont save it - just run it

you'll get a warning about the truncate not being supported for a graphical display, but it can still be executed.

note: if your table is named 'objects' then the sql would be

TRUNCATE TABLE objects;

|||
I have used the code from your recommended website, but don't know what is my 'schema_name', could you please advice me where I can find this in my 'Server Explorer'?
this is what i have changed so far - is it right to leave the name as it is i.e.Objects_name ? also is it right to keep all the brackets and full stops?
TRUNCATE TABLE     [ { LTrails_name.[ schema_name ]. | schema_name . } ]    Objects_name[ ; ]
|||

if you right click your table and start to create a new query and add that table you'll get something like this:

SELECT FROM objects

the word 'objects' should already be your exact table name that you added to the query.

now you just need to replace the SELECT FROM portion of the query with TRUNCATE TABLE

TRUNCATETABLE objects

Then run the query.

|||

Your very detailed explanation is most appreciated,

No comments:

Post a Comment