Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Sorry if I sound ignorant but I'm new to SQL. I'm using SQL Server 2008. Basically I have a dbo object that displays a list of items, and when I hit "execute" the list refreshes with the most current data.
My question is this: is there a way to set this to execute automatically every minute or so while the table display is open? I plan on sharing out the view of the database so that people can see how far along the DB is before attempting to query it.
Hopefully that makes sense. I tried Google'ing but this seems like a rather vague topic or I'm just too confused to understand what some of these sites are saying. Any help at all would be greatly appreciated.
Clarification:
By "dbo object" I meant a table (I think?). For example it's named dbo.Bridge, and when I right click it I click "edit top 200 rows" to see the data, and then I click the red exclamation mark at the top of SQL Server 2008 to "Execute", which causes the table to update
If you're in SQL Server Management Studio or Visual Studio SQL Server Explorer then you won't be able to do it. You can set delays to execute, however:
WHILE (1 = 1)
BEGIN
SET NOCOUNT ON;
select * from [test_p]
WAITFOR DELAY '00:00:02'
END
This will keep appending onto the existing results, however, that is just a limitation of the software. It isn't meant to do things like this. You're better off just writing a simple script or view to execute every so often and display the data in some other way.
Try using waitfor, something like:
waitfor delay '000:01:00'
select * from MyTable
go 30
This will run the select 30 times, waiting a minute between each run.
(borrowed from Automatically refresh a query in ms sql server management studio?).
Another option would be to drop the query into a connection in an excel spreadsheet (for example), and set the background refresh options (workbook connections --> properties). This is most likely easier than keeping something running all day in sql server.
Edit: If GO does not work for you, check in options to see what word/character is set as your Batch Separator and replace GO with that word.
Related
I have just started an internship in I've had to learn a lot on my own. I'm learning MS SQL Server, but having a strange problem. I have a DB that has four small tables. Each one has a script to drop the table, recreate the table (I've avoided FK dependencies for the time being), and execute a demo query.
Problem 1: When I first started SQL Server Managmenent Studio would execute the script, but one table didn't show up in the Object Explorer. If I tried to execute a demo query from the same .sql file, it executed with no problem. If I tried to access it from another .sql, the table didn't exist. After many times of successfully executing the script, it finally just showed up.
Problem 2: Similar problem. When I updated one table, the changes wouldn't be reflected in queries.
Problem 3: Queries will fail, but if I click execute again with no changes being made, it will usually work correctly.
Problem 4: When I use an alias for a field name, sometimes the alias is recognized and sometimes it isn't. I've literally had single query in which the alias would work in one place, but not work in another and I had to use a fully qualified name.
I've tried the refresh and refresh local cache, but those seem to have no effect. If I exit Management Studio, that seems to usually fix the first two problems.
Am I going nuts or am I just in the dark about some weird specifics of SQL Server?
First of all, when you make a schema change you need to right-click on the "Tables" node for the database in management studio and hit refresh.
If you change a column or something in a table, right-click the table and refresh.
The refresh local cache only updates the intellisense stuff, and the refresh only updates the GUI. If you modify a table with SQL and do not refresh it in the UI, the query can still use the updated table.
If you query fails, you either have a bad query or it's not pointed at the database or connection you think it is.
For aliases, there are places where they will not work (update statements, for example) but if you don't post queries where they don't work we cannot read your mind and tell you what's wrong.
If you have specific queries that are failing, post them.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am using sql server 2005. In my project i wanna auto delete the data from the database after a fixed interval of time say (10 minutes); Is there any automatic process to delete the data from the database without the user intervention.. I want to use the event scheduler i have created a event scheduler but its not working any help ???
this is the event i have created.
CREATE EVENT deletedata
ON SCHEDULE
EVERY 10 MINUTE
DO
DELETE FROM user WHERE id=1
just go through the link Microsoft schedule Jobs
Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select 'New Job'
In the 'New Job' window enter the name of the job and a description on the 'General' tab.
Select 'Steps' on the left hand side of the window and click 'New' at the bottom.
In the 'Steps' window enter a step name and select the database you want the query to run against.
Paste in the T-SQL command you want to run into the Command window and click 'OK'.
Click on the 'Schedule' menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).
Click 'OK' - and that should be it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I have an SQL database - I need to back it up everyday (at a minimum) - preferably multiple times a day - automatically so it definitely gets done.
I'm running Windows which the SQL database is stored on.
What programs (prefer free ones) can I use to back it up - I'm completely new with SQL so if you're gonna explain something - do it in layman's terms thanks (:
It needs to get backed up to another server (on the LAN).
Auto Backup Database Using Maintenance Plans
Simple Step :
Go To SQL Server Configuration Manager > SQL Server Services > Run SQL Server Agent (Set it to Run Automatically)
Go To SQL Server Management Studio, Find TAB Management > Maintenance Plans. Right Click > Maintenance Plans Wizard.
Text your maintenance plans, ex: DailyBackup. Select Option button : Single Schedule for entire task.
Click Configure > Set Schedule according your demands.
Select Maintenance tasks. for this case, you choose Full Database backup.
Click Next, then define which database to backup, set backup location, and backup extension.
Click Next, Choose your report mode, then Finish.
There are many such programs at the moment, you can try EMS SQL Backup. It is not free but it is very handy for this type of tasks and supports backups compression, encryption and upload backups to FTP, network and cloud locations.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
i have a database and want to copy all the tables in new database without copying the dat of all those tables only structure should be copy
SQL Server Management Studio offers the following:
Scripting the whole database:
Under the Object Explorer, right mouse click on the database and then select Script Database as
To script just (specific) tables:
In Object Explorer, right mouse click on the database, select Tasks, then Generate Scripts, and then select the tables that you want.
You can then use the script to create a new database / new objects elsewhere. If you change the name of the database, remember to change the USE xxx statement(s) accordingly.
In SSMS for your first database right click on the datbaase name then "Script Database as" > "CREATE To" then choose your output location and run your script.
Edit:
Note you will need to amend the script to specify the new database name, replacing the existing one in the generated script (courtesy of Oded comment).
In the SQL server Management Studio you can right click the database -> tasks -> export data. Then follow the wizard..
This question already has answers here:
How Can I Log and Find the Most Expensive Queries?
(6 answers)
Closed 2 years ago.
I need to profile a large SQL query (in a particular database, not the whole server), and I cant figure out how to setup the profiler. I tried reading MSDN SQL web site, but it has not helped.
I am stuck at the Trace Properties "Events Selection" window. I need help as to which items to select in "Events Selection" window.
I am more interested in finding out why the query is not populating the tables (as opposed to performance)
Thanks
If by large SQL query, you mean a large stored procedure that contains multiple individual statements and you want to profile each of those statements when the sproc is called (like this) then monitor the SP:StmtCompleted event. Otherwise, just choosing the "Standard" profile template should suffice.
One of my first ports of call when looking into poor performance of a query would be to look at the execution plan though - that will tell you where the time is being spent.
I usually use the following setup. As Mich said it depends on what you want tho.
On the General tab select
TSQL_Duration from the "Use the
template:" drop down list.
On the events selection tab select
RPC:Completed if your watching a
stored proc or SQL:BatchCompleted if
you are just watching for queries.
Check all boxes to the right.
You can monitor different events based on the template you use. I have also found "Tuning" to come in handy.
There might be a TON of other stuff that comes up so you may want to filter what is displayed by editing some of the information that comes up when you click the "Column Filters..." button.
Examples:
Duration over 3000 (3 seconds)
TextData has some text that is specific to your query ( %stored_proc_name% )