0

Every time a user comes to my page, a couple of local database tables are CREATED IF NOT EXISTS. Then the records for these tables are queried from the Actual Database and inserted into the local database.

Is there a way to tell if a table has "Just been created" or if it "Already existed", so I do not have to call the "Actual Database" and prevent getting duplicate records?

Thanks!

3
  • I'm not sure I understand the difference between "local database" and "actual database". What type of SQL are you using - TSQL? Why are you creating an extra database if a database with relevant data already exists? Commented Mar 13, 2012 at 20:01
  • That's a good question. I'm using a Local Database (similar to this html5 ex: blog.darkcrimson.com/2010/05/local-databases). I also have a database in the back end, which holds all the data. My goal is to populate the local database with data from the actual database. This way the user has access to data that exists in the actual database and can still interact with the page. Commented Mar 13, 2012 at 20:27
  • My question is that is there a built-in or easy way to find if a table already Exists or if it has Just been Created. Knowing this definitely reduces the transfer of Request/Response data. I'm thinking about selecting to see if a table exists, but I'm not sure that would be the best idea. Is there some type of built in function to check whether a table exists? Commented Mar 13, 2012 at 20:30

1 Answer 1

1

You could count the number of rows in your local database. If the number is zero, then it's likely the table was just created.

Alternatively, if you have a strictly-increasing column, you could ask for the largest value. If no value returns, ask the server for all the rows. If a value is returned, ask the server for all rows greater than the value. This would keep your local database in sync with your "actual" database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.