I am writing a stored procedure that will export data from one table to another but not quite sure the right way to go about it. .
also. . when writing queries for mySql you can test for the existence of a table (DROP TABLE IF EXISTS tablename;) but this syntax does not fly in MS SQL.. . is there a way to do this when writing for MS SQL?
TIA
I believe the proper MSSQL syntax would be:
IF EXISTS(SELECT TABLE_NAME FROM DBNAME
WHERE TABLE_NAME = 'table_name')
DROP TABLE table_name
As for reference material, I'll second toadhall's recommendation of searching for SQL references. There are too many good ones to list here.
I have books too. .
But as Bono put it. . "I still haven't found what I'm looking for".. .
the syntax checks out for your suggestion on the conditional statement,
hasbeen, thanks. .
just gotta get it to execute now. . doesn't seem to like anything after 'FROM'.. .
For copying data from one table to another:
INSERT INTO destination_table SELECT * FROM source_table;
or to create the table at the same time:
CREATE TABLE new_table SELECT * FROM source_table;
hope this helps
thanks PPG!
-mattur - would that be the same as BooksOnline, documentation for MS SQL Server? or is it documentation on *writing* Structured Query Language for MS SQL?
thanks all. .
E