SQL Server 2012 :: Altering All Objects To Find Syntax Errors
Jul 25, 2014
How to alter all objects in database i want to find if can any syntax errors in my database after restoring from sql 2008 to 2012. I Can create as test and drop them but trying to find a way to alter proc , views and functions..
Question- Why am I getting 428 pages for which there is no corresponding DB object? Why are so many pages present in sys.dm_os_buffer_descriptors but are missing from sys.allocation_units.
passing serialised objects to a stored procedure for the purpose of data inserts. I see this as being a way to handle multiple row inserts efficiently.
However, in my limited use of XML data I am not so sure how to link the data when I have a dependency on another "object" within the serialised XML.
Below is a code snippet showing what I have so far.
The first insert statement works fine - but how to retrieve the identifier created by the DB - I want to use an SQL statement that finds the record in the table based on the XML representation (of the PluginInfo), allowing me to insert the ConfigurationInfo with the correct reference to the PluginInfo
DECLARE @Config NVARCHAR(MAX) DECLARE @Handle AS INT DECLARE @TransactionCount AS INT SELECT @Config = ' <ConfigurationDirectory > <ConfigurationInfo groupKey="Notifications" sectionKey="App.Customization.PluginInfo"
Hi. I'm totally new to SSIS (SP1), and I'm having a raft of troubles transferring DB's using the 'Transfer SQL Server Objects Task', which seems to be the closest replacement for the old DTS Transfer Objects tool.
I'm trying to transfer a DB from an SQL Server 2000, where I only have SQL Server authentication (it's a shared hosting environment) to my local SQL Server 2005 server, where I'm logged in using Windows Authentication (although I have the same issues if I use SQL Authentication locally).
Here's the list of errors I'm getting. If I don't select 'copy all tables', I receive a "table does not exist at source" error. If I do copy all tables, suddenly it can find the same table.If I select "Drop objects first", and the object doesn't exist in the destination, in throws an error.The "replace data" doesn't appear to work - it throws a "cannot insert duplicate key" error if the table I'm copying already contains data.If I copy Primary Keys, and one of the tables doesn't have a primary key, I get a "set identity" error, presumably because it's trying to set an ID on that table at the destination.Finally, if I delete all data at the destination, I'm currently receiving a "Invalid character value for cast specification". Which I don't get at all - why is it casting at all, if it's copying objects - they should be identical on both sides?Any and all suggestions would be really appreciated. I'm also having (different) problems transferring objects between SQL Server 2005 servers, but nothing in production, so it's less important.
I keep receiving the following error whenever I try and call this function to update my database.
The code was working before, all I added was an extra field to update.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'
Public Sub MasterList_Update(sender As Object, e As DataListCommandEventArgs)
Dim strProjectName, txtProjectDescription, intProjectID, strProjectState as String Dim intEstDuration, dtmCreationDate, strCreatedBy, strProjectLead, dtmEstCompletionDate as String
Dim myConnection As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionstring")) Dim cmdSQL As New SqlCommand(strSQL, myConnection)
I have a sp. I alter stored procedure by adding some logic to that. How can I test that is there any functional impact by altering that stored procedure? How to prove to the team that the modifications doesn't impact any functionality?
I am writing a script to get all of the user objects out of a database. What I am having a hard time doing is filtering out the MS replication system objects, such as:
As I was developing my SSIS package, I created several variables and tasks ( FTP, WMI Reader Task ). I am now cleaning up, deleting unwanted variables and connections in the design window. I save and build the package and when I load the package, I get warnings that these variables are referenced but can't find them and errors that the WMI connection is not found.
When a package calls a sub-package, it stores the absolute path of the child package in its dtsx xml file in a Connection String property. How annoying !!! . When I deploy this to another machine with a different file structure, it becomes a problem. Why can't it store the path relative to the parent package, which would be typically in a sub-directory under the parent ?
These last 2 days have been nothing but frustration and my deadline is slipping. Any help is appreciated.
Using import task only can select and copy tables and views.
Since there are many objects at the same DB I don't need copy, is there any way let me select and copy some objects, such as functions, stored procedures?
How i can find out the changes happened in database like modifying functions,table indexes,procedures and adding or removing columns..here in this query
select * from sys.objects where type IS NOT NULL and modify_date between '2013-07-21' and '2013-07-29'
but here i am getting created objects list and modifying list.but if i deleted any object it is not showing anything..how can i get the all the changes happened in database between specific dates.
I have a SQL Server 2005 database running. When I run some ddl changes, I want to find all the procs/objects that get invalidated because of object not found error.....
Is there any way that I can look up in sysdepends or other tables to find information about this.
What is wrong with my syntax?I want to return the value of the AchiveYear Value based on records in theCall that match.
SELECT DATEPART(yyyy,Call_Date) AS ArchiverYear FROM tblCall INNER JOIN PrismDataArchive.dbo.ArchiveDriver AS Arch ON tblCall.DATEPART(yyyy,Call_Date) = Arch.ArchiveYear
Hi Dears Below is the Sp that i want to use but there are many Syntax erros plz verify and correct them Thnx
create procedure CheckStatus
@EmpID int as -- i need some variables so i declared them declare @ShiftId int declare @DayTime smalldatetime declare @ShiftStartT smalldatetime declare @ShiftEndT smalldatetime declare @ShiftInOutStatus int declare @ShiftValidity bit declare @RTValue int
-- Now i m assigning the values to the declared variable by selecting some value from tables -- from this point i m having syntax erroes i dont know what are they all atables and all fields are ok verified
set @ShiftId=SELECT S_Id FROM Emp_Info WHERE Emp_Info.Emp_Id=@EmpID set @DayTime=SELECT GETDATE() set @ShiftStartT=SELECT S_ST FROM Emp_Shift WHERE Emp_Shift.S_Id=@ShiftId set @ShiftEndT=SELECT S_ET FROM Emp_Shift WHERE Emp_Shift.S_Id=@ShiftId set @InOutStatus=SELECT IOStatus FROM Emp_Status WHERE Emp_Status.Emp_Id=@EmpId -- here i m using a nested case for some checks to insert values into tables CASE -- Main Case WHEN @InOutStatus=0 OR @InOutStatus=-1 -- Calling udf_IsShiftValid(datetime,datetime,datetime) a function that ia also ok and returns two possible value 0 or 1 THEN @ShiftValidty=udf_IsShiftValid(@ShiftStartT,@ShiftEndT,@DayTime) CASE --nested case starts here WHEN @ShiftValidity=1-- Insertin value into Emp_Status table and assihning value to @RTValue THEN (INSERT INTO Emp_Status(IOStatus) VALUES(@ShiftValidity) WHERE Emp_Status.Emp_Id=@EmpID SET @RTValue=1) WHEN @ShiftValidity=0 THEN SET @RTValue=-1 END-- Nested case End Here WHEN @InOutStatus=1 THEN INSERT INTO Emp_Status(IOStatus) VALUES(0) WHERE Emp_Status.Emp_Id=@EmpID SET @RTValue=0 END
Select Sum(Cost) as Cost, Case When PymtRmID = 'Net 10' then (TodaysDate)+10 else pymtrmid end From #ttNonWires Group By Case When PymtRmID = 'Net 10' then (TodaysDate)+10 else pymtrmid end
Im trying to show obviousally when something when PYMTRMID says net10 i want todaydate +10 days in the column next to it i keep getting
Server: Msg 241, Level 16, State 1, Line 1 Syntax error converting datetime from character string.
-- This stored procedure will let you search through your database -- to find various objects that contain a particular string. -- For example, you may want to see all tables and views that contain -- a particular column.
use master IF (object_id('sp_FindReferences') IS NOT NULL) BEGIN PRINT 'Dropping: sp_FindReferences' DROP procedure sp_FindReferences END PRINT 'Creating: sp_FindReferences' GO CREATE PROCEDURE sp_FindReferences ( @string varchar(1000) = '', @ShowReferences char(1) = 'N' ) AS /****************************************************************************/ /* */ /* TITLE: sp_FindReferences */ /* */ /* DATE: 18 February, 2004 */ /* */ /* AUTHOR: WILLIAM MCEVOY */ /* */ /****************************************************************************/ /* */ /* DESCRIPTION: SEARCH SYSCOMMENTS FOR INPUT STRING, OUTPUT NAME OF OBJECT */ /* */ /****************************************************************************/ set nocount on
declare @errnum int , @errors char(1) , @rowcnt int , @output varchar(255)
/****************************************************************************/ /* INPUT DATA VALIDATION */ /****************************************************************************/
/****************************************************************************/ /* M A I N P R O C E S S I N G */ /****************************************************************************/
-- Create temp table to hold results create table #Results ( Name varchar(55), Type varchar(12), DateCreated datetime, ProcLine varchar(4000) )
IF (@ShowReferences = 'N') BEGIN insert into #Results select distinct 'Name' = convert(varchar(55),SO.name), 'Type' = SO.type, crdate, '' from sysobjects SO join syscomments SC on SC.id = SO.id where SC.text like '%' + @string + '%' union select distinct 'Name' = convert(varchar(55),SO.name), 'Type' = SO.type, crdate, '' from sysobjects SO where SO.name like '%' + @string + '%' union select distinct 'Name' = convert(varchar(55),SO.name), 'Type' = SO.type, crdate, '' from sysobjects SO join syscolumns SC on SC.id = SO.ID where SC.name like '%' + @string + '%' order by 2,1 END ELSE BEGIN insert into #Results select 'Name' = convert(varchar(55),SO.name), 'Type' = SO.type, crdate, 'Proc Line' = text from sysobjects SO join syscomments SC on SC.id = SO.id where SC.text like '%' + @string + '%' union select 'Name' = convert(varchar(55),SO.name), 'Type' = SO.type, crdate, 'Proc Line' = '' from sysobjects SO where SO.name like '%' + @string + '%' union select 'Name' = convert(varchar(55),SO.name), 'Type' = SO.type, crdate, 'Proc Line' = '' from sysobjects SO join syscolumns SC on SC.id = SO.ID where SC.name like '%' + @string + '%' order by 2,1 END
IF (@ShowReferences = 'N') BEGIN select Name, 'Type' = Case (Type) when 'P' then 'Procedure' when 'TR' then 'Trigger' when 'X' then 'Xtended Proc' when 'U' then 'Table' when 'C' then 'Check Constraint' when 'D' then 'Default' when 'F' then 'Foreign Key' when 'K' then 'Primary Key' when 'V' then 'View' else Type end, DateCreated from #Results order by 2,1 END ELSE BEGIN select Name, 'Type' = Case (Type) when 'P' then 'Procedure' when 'TR' then 'Trigger' when 'X' then 'Xtended Proc' when 'U' then 'Table' when 'C' then 'Check Constraint' when 'D' then 'Default' when 'F' then 'Foreign Key' when 'K' then 'Primary Key' when 'V' then 'View' else Type end, DateCreated, ProcLine from #Results order by 2,1 END
drop table #Results
GO IF (object_id('sp_FindReferences') IS NOT NULL) PRINT 'Procedure created.' ELSE PRINT 'Procedure NOT created.' GO
I'm trying to identify the objects in master that the role public has select permissions on, but when I run this query, I get 4 results where the default schema is null and the major_id column does not correspond to any records in the sys.all_objects table. Where else can I look to find what objects these are. DBO is listed as the grantor.
I appreciate your help.
SELECT * FROM SYS.DATABASE_PERMISSIONS P, SYS.DATABASE_PRINCIPALS R WHERE P.GRANTEE_PRINCIPAL_ID=R.PRINCIPAL_ID and permission_name='SELECT' and class_desc='OBJECT_OR_COLUMN' and r.name='public' order by r.name desc
I have an assignment to change names of the SPs that are not following Standard naming convention in all databases. For this first I need to find out all the SPs that are not following naming convention. Can anybody help me in finding out the objects that are not following standard naming conventions. It is first step in completing this assignment. If anybody deal with this type of task before please guide me. Hope any one of you will reply me with more information......
Hi all, I have the "Northwind" database in my Sql Server Management Studio Express.
In my C:ProSSEAppsSamplesForChapter02Chapter02 folder, I have the following 2 files: (1) ListColumnValues (MS-DOS Batch File) sqlcmd -S .sqlexpress -v DBName = "Northwind" CName = "CompanyName" TName = "Shippers" -i c:prosseappschapter02ListListColumnVales.sql -o c:prosseappschapter02ColumnValuesOut.rpt (2) ListColumnValues (Microsoft SQL Server Query File) USE $(Northwind) GO SELECT $(CompanyName) FROM $(Shippers) GO When I ran the following SQLcmd: C:ProSSEAppsSamplesForChapter02Chapter02>ListColumnValues.bat I got the following "ColumnValuesOut.rpt" with error messages:
'Northwind' scripting variable not defined. Msg 102, Level 15, State 1, Server L1P2P3SQLEXPRESS, Line 1 Incorrect syntax near '$'. 'CompanyName' scripting variable not defined. 'Shippers' scripting variable not defined. Msg 102, Level 15, State 1, Server L1P2P3SQLEXPRESS, Line 1 Incorrect syntax near 'CompanyName'.
I copied these T-SQL statements from a book and I do not know how to correct them. Please help and tell me how to correct these errors.
SET @Test1 = N'select * from table1 where column1 in (' + @Test + ')'
EXEC sp_executesql @Test1
If I put it in a "Begin Transaction" block
there is a syntax error near the ( in the set @Test1 statement.
If I leave it out of a "Begin Transaction" Block,
The syntax error is:
Server: Msg 105, Level 15, State 1, Line 1 Unclosed quotation mark before the character string ''. Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near ''.
I've created multiple select statement to pull in varies fields from a table and one of those fields is Fiscal_Year, however, after the select statement I'm adding a Where clause:
create proc dbo.sp_GetInvitationsHistoryDetails(@ExecID int, @OrgID int) as IF (@OrgID = 0) BEGIN select E.EventID,E.Description as Event,E.EventDate as Date I.Attending as [Att'g],NotAttending as [Not att'g],I.Bootcamp as [Maybe] I.Attended FROM Invitations I INNER JOIN Events E on I.EventID=E.EventID WHERE I.MemberID=@ExecID and NotForStats=0 ORDER BY E.EventDate DESC END ELSE BEGIN select E.EventID,E.Description as Event,E.EventDate as Date count(*) as Invited,SUM(CONVERT(smallint,I.Attended)) AS Attended FROM Invitations I INNER JOIN Events E on I.EventID=E.EventID WHERE I.MemberID IN (select ID FROM Executives WHERE OrganisationID=OrgID GROUP BY E.EventID,E.Description,E.EventDate ORDER BY E.EventDate DESC END
and i'm getting the following syntax errors when i check it -
Msg 102, Level 15, State 1, Procedure sp_GetInvitationsHistoryDetails, Line 10
Incorrect syntax near 'I'.
Msg 102, Level 15, State 1, Procedure sp_GetInvitationsHistoryDetails, Line 19
Incorrect syntax near 'count'.
Msg 156, Level 15, State 1, Procedure sp_GetInvitationsHistoryDetails, Line 23
Incorrect syntax near the keyword 'ORDER'.
Originally i just ran this sql from C# and it worked, obviously added the @ to the variables but it's basically the same.
Could anybody tell me how can I find all the database objects that are used in /referenced by/called by/dependent on a given stored procedure? In other words, I am looking for something like a stored procedure or a function that takes as input the name of a stored procedure and outputs all the names of the tables, functions, procedures, cursors and etc. database objects that are used in that procedure. Could you please give me suggestions or possible answers for this?
I am having 100 of flat files need to load in respective staging table.I want to create table on run time as per filename input.suppose if input filename is ABC then table name should be Staging_ABC if file name is XYZ then it should be Staging_XYZ.Table structure is below need to create at run time
CREATE TABLE Staging_'Filename'( [COL001] [varchar](4000) NULL, [Id] [int] IDENTITY(1,1) NOT NULL, [LoadDate] [datetime] NOT NULL default getdate() )
I am getting error when I am trying to create table on runtime
Declare @FileName varchar(100) Declare @File varchar(100) set @FileName='brkrte_121227102828' SET @File = SUBSTRING(@FileName,1,CHARINDEX('_',@FileName)-1) --=select @File
[Code] ....
Error massage:- Msg 203, Level 16, State 2, Line 16
The name 'CREATE TABLE DataStaging.dbo.Staging_brkrte ( [COL001] VARCHAR (4000) NOT NULL, [Id] Int Identity(1,1), [LoadDate] datetime default getdate() )' is not a valid identifier.