I have a database of 40 tables. I want to track the changes and keep record of every change made in database. what would be best option ?
Note: i am using MS SQL Server 2005.
i have tried following code for Change Tracking
ALTER DATABASE Customer
SET CHANGE_TRACKING = ON
(AUTO_CLEANUP = ON , CHANGE_RETENTION = 5 DAYS)
but gives error
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'ON'.
if anyone could help me on this issue, i would be greatful.
You might give C2 auditing a try: http://msdn.microsoft.com/en-us/library/ms187634%28SQL.90%29.aspx
I believe you are trying to use a 2008 feature.
Related
The following SQL statement fails on SQL Server 2012(SP1) 11.0.3401.0 Version
DECLARE #b VARCHAR(10) = '12312.2'
SELECT TRY_CONVERT(DECIMAL(10,2),#b)
error message
Msg 195, Level 15, State 10, Line 2
'DECIMAL' is not a recognized built-in function name.
But works fine on SQL Server 2012(SP1) 11.0.3393.0
Both servers have no problem with TRY_PARSE()
DECLARE #b VARCHAR(10) = '12312.2'
SELECT TRY_PARSE(#b AS DECIMAL(10,2))
Update:
after further testing and trying conversion to different types got another different error message
DECLARE #b VARCHAR(10) = '12312'
SELECT TRY_CONVERT(INT,#b)
Error:
error: Msg 195, Level 15, State 10, Line 2
'TRY_CONVERT' is not a recognized built-in function name.
So original error message was miss leading, but now I'm even more confused why it is not there.
Check that the database compatibility level for the particular database you are using the function in is set to SQL Server 2012 (110) under properties/options/compatibility level for the database.
Make sure that you have specified on which database you want to run the query on.
use [Database_Name]
go
>>>>query here <<<
go
In my case I had a number of different databases on the server with different compatibility levels.
You can run the following script to Upgrade your database compatibility level to SQL Server 2012 (110):
if (SELECT compatibility_level FROM sys.databases WHERE name = '[Your_Database_Name]')<120
begin
ALTER DATABASE StreamNet
SET COMPATIBILITY_LEVEL= 110
end
Note: Replace [Your_Database_Name] with your current database name.
Reference: See Microsoft solution for more details
Try another IDE or environment to see if isolates the error? I was getting this error running a query in Azure Data Studio. When I ran the same query in SQL Server Management Studio -- where I'd first written it -- it ran successfully.
I'm running SQL Server 2008 R2. I'm trying to build a table that takes data from a table structured like this:
company | ded_id | descr
10 1 MEDINS
10 2 LIFE
10 3 PENSN
...
10 50 DOMREL
And I need to build a temp table it out to a format like this:
company | DESC1 | DESC2 | DESC3 ... | DESC50
10 MEDINS LIFE PENSN DOMREL
So I built the following query:
SELECT *
FROM (
SELECT company,'DESC'+CAST(ded_id as VARCHAR(2)) AS DedID,descr
FROM deduction
) deds
PIVOT (MAX(descr)FOR DedID IN([DESC1],[DESC2],[DESC3])) descs
So running this gives the following error:
Msg 325, Level 15, State 1, Line 6
Incorrect syntax near 'PIVOT'. You may need to set the compatibility level of the current database to a higher value to enable this feature. See help for the SET COMPATIBILITY_LEVEL option of ALTER DATABASE.
I double checked the compatibility level on the database and it is already set to 100 so that can't be the issue. Can you think of any other setting that might be causing this behavior?
The possible reason for that type of issue is you imported database from other source which might be running older version of SQL Server. Anyway, you have way to get out of it. Follow steps below:
Right click on Database (e.g. Northwind).
Click 'Properties'.
Click 'Options', from left pane, under 'Select a page' section.
Select appropriate database version as per your installation from drop-down of 'Compatibility level' at right.
Save changes and try now.
Below is screenshot of Properties window for your reference.
I had the same error (Incorrect syntax near 'PIVOT'...) and solved it by changing compatibility level in the Options section of database properties.
I also found how to script the compatibility level change:
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = 100
(see https://msdn.microsoft.com/en-us/library/bb510680.aspx?f=255&MSPPError=-2147217396)
i faced the same problem... while using "Pivot" and "Format" and "Convert" command inside sql query.
one thing that worked for me was
instead of importing sqlite
i imported pyodbc
so my code changed
from :
import sqlite3
conn = sqlite3.connect('/Users/****/Desktop/****.sqlite')
to:
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};''Server=####;''Database=****;' 'Trusted_Connection=yes;')
I know it's not the same thing that was asked, but it solved it for me and it can help other people. pivot and a SQL reserved word, so it presents the error, what solved it was to put it in square brackets.
select * from ledgers where [pivot]
I am using Sql Server 2005.
I wanted to take back up of my database through simple sql command.
For this I referred THIS document.
Made command as follows:
backup database webbasednewsoft to disk 'e:\wb.bak'
but its giving me error as:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'e:\wb.bak'.
I dont understand what is syntax error in this?
I have made everything according to doccument.
I thought the issue was for escape sequence, hence i also tried,
backup database webbasednewsoft to disk 'e:\\wb.bak'
But the error was same.
Please guid me for this.
You need an = sign.
backup database webbasednewsoft to disk='e:\wb.bak'
See here for the MSDN for the BACKUP command
And if you look at your reference it too mentions using an = sign! but hey we're all guilty of eager reading I know I do it... :-)
I've been using the code below:
CREATE DATABASE [NSFKIPRODDB01_BKBK] AS COPY OF [NSFKIPRODDB01] (EDITION='BUSINESS', MAXSIZE = 10GB)
But it keeps on throwing me the error below:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'AS'.
Can I ask why isn't a CREATE DATABASE AS COPY OF + ALTER DATABASE good enough?
I am creating a database by using following schema ...... using microsoft sql server....
CREATE DATABASE /*!32312 IF NOT EXISTS*/`stacks`/*!40100
DEFAULT CHARACTER SET utf8 */;(Line 15)
USE `stacks`;
/*Table structure for table `answers` */
Got An error like this ...while executing , i dont know....
Error : Msg 102, Level 15, State 1, Line 15
Incorrect syntax near '`'.
would any one pls help on this.....
Many Thanks in advance ....
Did you look up SQL Server CREATE DATABASE and identifier syntax?
All you need is CREATE DATABASE stacks;
Your code is for MySQL
It looks like your syntax is from MySQL. Why do you have back-ticks and "default character set"? This is not SQL Server syntax. Please see the SQL Server docs for CREATE DATABASE: http://msdn.microsoft.com/en-us/library/ms176061.aspx