Transact SQL :: Check DB Consistency After DROP COLUMN
Apr 25, 2015
I have a SQL Server 2005 DB in which a design change requires me to drop a column.Is there a way of identifying all references in the DB including functions & stored procs's that reference this column? I understand there are 3rd party products that can do this but was wondering if there was something baked into SQL Server itself.
View 8 Replies
ADVERTISEMENT
Feb 16, 1999
When my Backup Exec runs a Consistency check on tempdb I keep getting this error:
Allocation Discrepancy: Page is allocated but not linked; check the following pages and ids: a `location pg#=512 extent id=560 logical pg#=560 object id on extent=-1168007832 (ob `ect name = -1168007832) indid on extent=1.
What does this mean exactly, and what do I need to do?
Thanks if you can help.
Andrew
View 3 Replies
View Related
Oct 19, 2015
how to do a check for 2 columns. As long as there is data for at least one of the columns I want to return rows.
Example Data
create table test
(
ID int,
set1 varchar(50),
set2 varchar(50),
[code]....
View 4 Replies
View Related
Nov 1, 2007
Trying to clean up after installing several SQL servers on a server. Started by installing SQL2000 enterprise as a named instance. Then added a instalation of SQL2005 enterprise again as a named instance. Then renamed OS level Server / Computer name. Now want to rename the SQL Servers or drop and then re add.
Anyway a long story short I have searched many boards and tired a bunch of things but still I come back to How can I remove things that show up in the list when you use the osql /L command from a command prompt.
Here are several things I have either tried or checked with many different varaitions:
SELECT @@SERVERNAME
SELECT SERVERPROPERTY ('MachineName'), SERVERPROPERTY ('InstanceName')
sp_helpserver
go
sp_dropserver 'MachineNameInstanceName'
GO
sp_addserver 'MachineNameInstanceName', local
GO
DECLARE @srv sysname
SET @srv = CAST(SERVERPROPERTY('ServerName') AS sysname)
UPDATE sysjobs SET originating_server = @srv
If this is a target server (you have jobs sent from a master server), you have to exclude them, so you don't convert those jobs into local jobs:
WHERE originating_server = '<old_name>'
View 4 Replies
View Related
Mar 7, 2008
Hi I’m trying to alter a table and delete a column I get the following error. The object 'DF__Morningst__LastU__19EB91BA' is dependent on column 'LastUpdated'.
ALTER TABLE DROP COLUMN LastUpdated failed because one or more objects access this column. I tried deleting the concerned constraint. But the next time I get the same error with a different constraint name. I want to find out if I can dynamically check the constraint name and delete it and then drop the column. Can anyone help.IF EXISTS(SELECT 1FROM sysobjects,syscolumnsWHERE sysobjects.id = syscolumns.idAND sysobjects.name = TablenameAND syscolumns.name = column name)BEGIN EXECUTE ('ALTER TABLE tablename DROP CONSTRAINT DF__SecurityM__DsegL__08C105B8')EXECUTE ('ALTER TABLE tablenameDrop column columnname)ENDGO
View 1 Replies
View Related
May 21, 2015
I have this script which generates droptable tablename.
select top 10000 'drop table '+name, * from sys.tables (nolock) where name like '%4[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' order by create_date
I would like to generate 'GO' after each drop statement.
View 3 Replies
View Related
Oct 13, 2015
I am trying to generate a script to drop 15 tables which have dependencies across the database. Is there a script that could generate the drop stataments based on the child table first , parent table last strategy?
View 3 Replies
View Related
Jan 21, 2010
What is the best way to drop a temp table if it exists? I am looking something similar to this: if exists (select top 1 * from #TableName) then drop #TableName else end
View 5 Replies
View Related
May 29, 2015
I have a procedure where an id is passed into the procedure. It will either be a numeric value or it will be the word "ALL." All that is taking place is a select statement for the specified user id. However, if All is passed in then I 1st need to get a list of all possible user id's and produce the results for all of the associated user ids. This is my syntax, but it keeps producing a compile error of:
Msg 3701, Level 11, State 5, Line 1
Cannot drop the table '#tbl_temp', because it does not exist or you do not have permission.And I placed a comment above the line that is throwing this error.
CREATE procedure [dbo].[TEST]
(
@id varchar(100),
@startDate datetime,
@endDate datetime
[code]...
View 10 Replies
View Related
Aug 20, 2006
I am using Visual Web Developer Express 2005 and SQL Server Express 2005.
I have set up a trigger that fires when an update has been performed on a specific table. The trigger checks to see if specific columns have been updated. If they have, then the trigger code is executed. This part works fine.
I am now trying to find a way to check if null values exist in either one of two field from the same table. If either field contains a null value, then I don't want the trigger code to be executed.
How can I check for null values and skip a block of code within my Transact Sql trigger.
Thanks.....
View 2 Replies
View Related
Nov 3, 2015
I have a webpage where users can connect with other users by sending them a request. Sending the request just puts a row in a connect table that contains the users id, the targetusers id, a requesteddate, an accepted date and a disconnectdate (for the original requester to end the connection and a reject bit the the target can reject the request. Hoever I need to check to assure that the connect does nt already exist either as pending (requestdate is not null and accept date is null) or both dates are not null (connection already complete.).
ALTER PROCEDURE [dbo].[requestConnect]
-- Add the parameters for the stored procedure here
@requestor int,
@requested int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.
[Code] ....
View 4 Replies
View Related
Jul 24, 2015
I have included in the attached SQL:
Declare @table1 table
(
cnsmr_id int,
complainid int,
complaintstat varchar(10)
)
Insert into @table1
[Code] ...
The query should return only cnsmr_id=2 since all the complaints is closed (blank/NULL) i have achieved this using having but is there is more performance way of doing this?
View 5 Replies
View Related
Sep 29, 2015
How can I check the overlapping in a simple table like:
Create table forum (cid int, bfrom date, tfrom date, fval int)
Insert into forum values (1, '2014-01-01', '2014-01-31',10),(2, '2014-01-01', '2014-01-31',12),(1, '2014-02-01', '2014-02-28',8),(2, '2014-02-01', '2014-02-28',6),(1, '2014-03-01', '2014-03-31',11),(2, '2014-03-01', '2014-03-31',5),(1, '2014-04-01',
'2014-04-30',14), (2, '2014-03-01', '2014-04-30',12)
In the example above there is an overlapping for the cid 2 in March. How can I check, which select should I apply?
View 5 Replies
View Related
Jul 20, 2015
I'm wondering if its possible to return the number of files in a folder suing something like DIR command.I'm wanting to do something like, If count(DIR) >0 then do something
else End
exec master.dbo.xp_cmdshell
'dir C:Test'
View 2 Replies
View Related
Feb 14, 2000
Does anyone know why this does not work?
ALTER TABLE deal DROP COLUMN TestField
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'TestField'.
Thanks,
Paul
View 4 Replies
View Related
Aug 30, 2006
Hi:
'Unfortunately', there is still a SQL6.5 sp4 server that I need to handle.
I need to drop a coulmn xyz from an important table tblABC.
But neither Enterprise manager could do it nor
'alter table tblABC drop column xyz' could run.
Without the hastle of makin a tblABCcopy and copy all data from tblABC except column xyz and re-do all fks; is there another way to drop the column?
thanks
-D
View 1 Replies
View Related
Apr 6, 2015
I have a question, Every month I get a request from cutomer service to go into a SQL VIEW and DELETE a column to reflect the past Month. How to write a query to create a SQL job to performed this task automatically. For example today I deleted the column [2015/03] which represents the month of March. The columns left are [2015/04] representing the current month, [2015/05], [2015/06],[2015/07]....[2016/08].Next month I will have to delete column [2015/04]and the current month will be [2015/05]....etc.
So I'm thinking I will have to Drop the column and also Maybe using a date funtion to look at the current date and format it to reflect [YYYY/MM] and IF the Column Month is less than current date month then drop the column.
View 3 Replies
View Related
Mar 15, 2007
How to drop single column in a table.........
View 3 Replies
View Related
Oct 8, 2015
I'm trying to figure out the best way to write a script to deploy environment variables to different servers. To create the variable I'm currently using catalog. create_environment_variable. I want to wrap that in an if not exist statement.I had thought about just blowing away all the variables and recreating them but I thought that wouldn't go over well in prod. I wasn't sure if by deleting the variable, references to the variable would be lost.
View 3 Replies
View Related
May 12, 2015
I am trying to write a SQL Server query that archives x-days old data from [Archive].[TestToDelete] to [Working].[TestToDelete]table. I want to check that if the records on ArchiveTable do not exist then insert then deleted...which will be converted to a proc later.. archives x-days old data from [Working].[TestToDelete] to [Archive].[TestToDelete] table */Here is the table definition, it is the same for both working and archive tables. There are indexes on: IpAddress, Logdate, Server, User and Sysdate (clustered).
CREATE TABLE [Archive].[TestToDelete]([Server] [varchar](16) NOT NULL,[Logdate] [datetime] NOT NULL,[IpAddress] [varchar](16) NOT NULL,[Login] [varchar](64) NULL,[User] [varchar](64) NULL,[Sysdate] [datetime] NULL,[Request] [text] NULL,[Status] [varchar](64) NULL,[Length] [varchar](128) NULL,[Referer] [varchar](1024) NULL,[Agent] [varchar](1024) NULL) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]/* the syntax, which will be converted to proc is: */SET NOCOUNT ON;DECLARE @Time DATETIME,@R INT,@ErrMessage NVARCHAR(1024)SET @R = 1/* set @Time to one day old data */SET @Time =
[code]....
View 8 Replies
View Related
Aug 20, 2015
Basically, I have a membership table that lists each member with an effective period, Eff_Period, that indicates a month when a member was active. So, if a member is active from Jan to Mar, there will be three rows with Eff_Periods of 201501, 201502 and 201503.
All well and good.But, a member may not necessarily have continuous months for active membership. They might have only been active for Jan, Feb and Jun. That would still give them three rows, but with noncontinuous Eff_Periods; they'd be 201501, 201502 and 201506.There is also a table that logs member activity. It has an Activity_Date that holds the date of the activity - betcha didn't see that comin'. What I'm trying to do is determine if an activity took place during a period when the member was active.
My original thought was to count how many rows a member has in the Membership table and compare that number to the number of months between the MIN(Eff_Period) and the MAX(Eff_Period). If the numbers didn't matchup, then I knew that the member had a disconnect somewhere; he became inactive, then active again. But, then I thought of the scenario I detailed above and realized that the counts could match, but still have a discontinuity.So, is there a nifty little SQL shortcut that could determine if a target month is contained within a continuous or discontinuous list of months?
View 14 Replies
View Related
Oct 14, 2015
I am using aloha POS and they have the date for every check in separate fields and now I want to calculate the total time for the checks but unable to get the how of it..
The date is DOB and it's datetime but I just need to extra the getdate() from it.The open time is OPENHOUR and OPENMINThe close time is CLOSEHOUR and CLOSEMIN
so basically the open time for the check will be the DATE FROM DOB + OPENHOUR + OPENMIN
And the close time will be DATE FROM DOB + CLOSEHOUR + CLOSEMIN
How can I get the total minutes for the check?
View 2 Replies
View Related
Sep 14, 2015
I want to check that no inserts are occurring in 5 tables that are depending on each other and then drop and create those 5 tables. I have scripts to drop and recreate the tables. How do I check that no inserts are happening in these 5 tables?
Table A
Table B dependant on
Table A
Table C dependant on
Table B
Table D dependant on
Table C
Table E dependant on
Table D
View 9 Replies
View Related
Nov 2, 2015
Is it possible to check if the date has been formatted as dd/mm/yyyy i.e. something like this...
if (@EnterDate <> dd/mm/yyyyy )
SET @message = 'date not in the correct format'
View 4 Replies
View Related
Aug 21, 2015
query that checks to see if a variable contains special characters; except for hyphens, periods, and accents?
View 3 Replies
View Related
Aug 5, 2015
I have a table that keeps track of all changes that were performed in an application. There is a column called "old value" and column called "new value". There are some values in the application that don't require data therefore the "old value" or "new value" values can be empty. These columns are an nvarchar data type because the value can be text or numbers or dates. An example is "ReceivedDate". There is a report that is generated based on this table.
What is happening is the query in the report dataset is adding dates when it should be displaying empty. They query is using "CASE/WHEN/THEN". What I need is "When the column is "RecievedDate" and it is not null then convert it to a date". This is for formatting purposes.
This is an example of the table:
UpdateColumn
Old Value
New Value
ReceivedDate
7/8/2015 5:00:00 AM
ReceivedDate
7/8/2015 12:00:00 AM
7/9/2015 5:00:00 AM
ReceivedDate
7/9/2015 12:00:00 AM
So, the first time it was updated there was no value but it was replaced with July 8, 2015 and so on.This is what the report is displaying
This is the query:
CASE UpdateColumn
... WHEN 'ReceivedDate' THEN (replace(convert(varchar(11),CONVERT ( date, oldvalue ), 106), ' ', '-') )
...
I tried adding
CASE UpdateColumn
...
WHEN 'ReceivedDate' IS NOT NULL
THEN (replace(convert(varchar(11),CONVERT ( date, oldvalue ), 106), ' ', '-') )
...
But it did not like the "IS NOT NULL".
View 9 Replies
View Related
Apr 24, 2007
I checked column from xsd file which created from DataBase.
And before installing my application I will check any column in destination base whether have complete column or not.
And if there is any column which is not wanted column(not same as xsd structure)
I will delete it by creating sql command as follow "ALTER TABLE tableName DROP COLUMN column1, column2, ......"
and Execute it by program initialization.
So
I need delete it by run-time
However some column may be Primary Key with any reason
That's why I can't delete them by simple command
I expect to delete them by specific column instead of specific constraint name which is not sure name.
Please advise me....
View 2 Replies
View Related
Aug 2, 2001
Hi all,
how can I drop a column in a table.
View 1 Replies
View Related
Jun 13, 2008
I did this...
ALTER TABLE tm_spn_equip_def ADD Customer_No int NOT NULL DEFAULT dbo.f_spn_GetCustomerNo() WITH VALUES
Now when I attempt to do this...
ALTER TABLE tm_spn_equip_def DROP COLUMN Customer_No
I get an error:
Msg 5074, Level 16, State 1, Line 1
The object 'DF__tm_spn_eq__Custo__019E3B86' is dependent on column 'Customer_No'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN Customer_No failed because one or more objects access this column.
How can I get around this?
TIA!
View 4 Replies
View Related
Dec 13, 2007
Hi all!
One more question: how can i drop a column from a table?
Greetings
landau
View 2 Replies
View Related
Jul 20, 2005
Hello,I'm just returning to MS SQL Server after two years of dealing withSybase ASE. I need to drop a column, using the alter table command.I keep getting an error indicating that a constraint is using thecolumn. Here is the create script for the tablecreate table mytable(col1 char(1) not null,col2 char(1) default 'A' not null)Here is the alter table command:alter table mytable drop column col2When I run it I get the following error:Server: Msg 5074, Level 16, State 1, Line 1The object 'DF__mytable__col2__114A936A' is dependent on column'col2'.Server: Msg 4922, Level 16, State 1, Line 1ALTER TABLE DROP COLUMN col2 failed because one or more objects accessthis column.Is there anyway to tell the database to drop all column constraintswhen the column is deleted?Thanks,James K.
View 2 Replies
View Related
Oct 6, 2007
I have a database that I have made using sql server 2005 express edition. I want to run a query to drop one of the columns from one of the tables. I have tried the following but had no luck.
USE database
DROP column FROM table
This is the error that I got when I tried this.
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'FROM'.
Of course, my query had the real database, table and column names. I have generic ones that I have provided here.
Do I have to alter the table instead of dropping the column that I don't want?
Do I have to remake the table without the column that I don't want?
View 1 Replies
View Related
Sep 25, 2007
Hello !
I am using Microsoft SQL Server 2000
I am trying to drop a column that has a constraint, executing the script inside a transaction:
BEGIN TRANSACTION
ALTER TABLE MOPTeste DROP CONSTRAINT FK_IDMOPPais
ALTER TABLE MOPTeste DROP COLUMN IDMOPPais
COMMIT
If i dont commit the drop constraint, it wont let me drop the column
Solutions?
View 3 Replies
View Related