But if you really don't want to check if each table exists, for instance when you are sure you need to start from scratch, you could start with dropping the database if it exists: IF EXISTS (SELECT * FROM sys. So after the GO continue with: IF OBJECT_ID('MyTestTable', 'U') IS NULLĪs already mentioned by others it is good practice to check if every table exists and do a create action if it doesn't and alter action if it does (or just do nothing). Create a table, starting in Design view In Design view, you first create the table structure. In this case it is inadmissible because it is not possible to combine CREATE DATABASE and CREATE TABLE statements in one batch. Now you can start using your just created database with: USE MyTestDataBase Īgain, mind the GO statement. If you don't use GO SSMS (or any other client) will still think your batch is not completed, your database is still not created and therefore not available for further use, and you get the error message you posted. To change the location of the file from the default, click Browse for a location to put your database (next to the File Name box), browse to the new location, and then click OK. Obviously you have to start with (and mind the GO here): USE masterīut you have to do it like this: IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'MyTestDataBase') Create a blank database On the File tab, click New, and then click Blank Database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |