Query Help

  • Okay here is my situation, I have a database that I had on my website and I want to use it for my class project. Well I'm sure it was MySQL not SQL but with some time I have gone in and fixed a lot of the code.

    Here is my problem being new to the whole SQL I am missing some of the basics and I have searched on the forums and Google but I don't think I'm asking the right question. I'm hoping you can help me understand what it is that I'm doing wrong.

    When I uploaded the .sql file it had 23,000 lines of code I am 50% done with fixing the issues but I saved the project and now I have no idea how to open all the lines of code. I know it has to be with New Query but how do I get everything. so I can see all the errors that it is creating and I can go in and fix them.

    Please ask me questions its the only way I can learn and understand the basics better.

    Thanks

    KC

  • Is it MySQL that you are working with? This site is dedicated to Microsoft SQL Server. You may have better luck on the MySQL.com Forums[/url].

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • nope its SQL...

  • What do you mean by "saved the project"?

    issues but I saved the project and now I have no idea how to open all the lines of code. I know it has to be with New Query but how do I get everything. so I can see all the errors that it is creating and I can go in and fix them.

    I think there may be some terminology problems. Please say step by step what you have done and at each step what you are having trouble understanding.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • 1. Old Website used SQL or MYSQL database.

    2. Exported database with phpmyadmin

    3. saved as a .sql file

    4. class project to create a database in 2008 SQL Server "Planned to use old database as project since it already has data in the fields"

    5. Opened SQL Server Management Studio

    6. Created new database "classproject"

    7. Clicked and dragged .sql file in to open window on server.

    8. I can view all the code that will create the tables.

    9. Clicked "Execute" came up will a few syntax errors..

    10. Started to fix errors- class ran out then I did two things

    11. backed-up database and saved database

    12. Came home to finish working on project " Im working all in VMware" so I can work on it at school and home.

    13. Opened server and went to "classproject" and now I do not see the 23000 lines of syntax or code that I have been fixing.

    14. There is where I need to get to.

    15. I went to the saved file from class and just did steps 7-8.

    16. How do I view the code without having to do that every time?

  • Chuck112 (2/17/2013)


    1. Old Website used SQL or MYSQL database.

    2. Exported database with phpmyadmin

    3. saved as a .sql file

    4. class project to create a database in 2008 SQL Server "Planned to use old database as project since it already has data in the fields"

    5. Opened SQL Server Management Studio

    6. Created new database "classproject"

    7. Clicked and dragged .sql file in to open window on server.

    8. I can view all the code that will create the tables.

    9. Clicked "Execute" came up will a few syntax errors..

    10. Started to fix errors- class ran out then I did two things

    11. backed-up database and saved database

    12. Came home to finish working on project " Im working all in VMware" so I can work on it at school and home.

    13. Opened server and went to "classproject" and now I do not see the 23000 lines of syntax or code that I have been fixing.

    14. There is where I need to get to.

    15. I went to the saved file from class and just did steps 7-8.

    16. How do I view the code without having to do that every time?

    When you say you saved it, did you save it by clicking save from within SSMS? If so, the default location will be in the My Documents\SQL Server Management Studio\Projects, and what you are saving is the .sql file. If you did not give it a name, it will probably be called 'SQLQuery1.sql'. Now, for some reason, on my desktop instance, it does not contain the 'projects' directory. When you open SSMS, you will have to open the file each time. I would also probably refrain from executing 23,000 lines of code all at once, but rather, would probably try to break it into logical blocks if you can.

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • Thank you for the replies.. everyone... So if I want to see the code each and everytime I will have to drag and drop that file in to my ssms to show all the code? How would you recommend breaking it down instead of one large file. The lines are the create table... then all the data that needs to go in to each table... its a large headache I know but I figure if I make it past this I will have a better understanding of SQL. I really enjoy working with SQL as odd as that might sound... I am also trying to learn MYSQL at the same time but Im in school and one class is database... SQL.. fun I know.

  • Chuck112 (2/17/2013)


    Thank you for the replies.. everyone... So if I want to see the code each and everytime I will have to drag and drop that file in to my ssms to show all the code? How would you recommend breaking it down instead of one large file. The lines are the create table... then all the data that needs to go in to each table... its a large headache I know but I figure if I make it past this I will have a better understanding of SQL. I really enjoy working with SQL as odd as that might sound... I am also trying to learn MYSQL at the same time but Im in school and one class is database... SQL.. fun I know.

    Yes, you will have to open the .sql file every time you want to work on it. However, you needn't drag and drop, you can simply open it directly from SSMS. You can either use file>open, or, even easier, click the file open button on the toolbar. Mine is located directly below the debug menu icon.

    By breaking it up into logical blocks, and this is just me, I would probably organize the code by object. For example, for a table, I would test for/drop, create, index, populate each one individually. But that is just me, and there is absolutely wrong with what you are doing if it works. If you are experiencing errors, though, it might be easier to find if you are running it one step at a time. Again, that's just me.

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

  • My errors are syntax errors... from the code... it gives me the line and code... the only thing i hate is the fact that I have to go to each - Create Table and put Drop Table above it so i don't create the same data each time i try to find the errors.

  • Chuck112 (2/18/2013)


    My errors are syntax errors... from the code... it gives me the line and code... the only thing i hate is the fact that I have to go to each - Create Table and put Drop Table above it so i don't create the same data each time i try to find the errors.

    Well, if you simply put 'DROP TABLE TableName', and it does not exist, you will also get an error. You should test for the existence of the table, then drop it only if you need to.

    IF OBJECT_ID('test..SomeTable','u') IS NOT NULL

    DROP TABLE test..SomeTable;

    Where you will replace 'test' with your database, and 'SomeTable' with your table name. While the three part naming convention is not required, I always include it, lest you inadvertently drop a table you did not mean to drop. I accidentally dropped the wrong table one time when I first started, and I had no backups. Needless to say, it was not a good situation.

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply