Check SQL Server Replication Defaults - sql-server

We have a database a that is replicated to a subscriber db b (used for SSRS reporting) every night at 2.45 AM.
We need to add a column to one of the replicated tables since it's source file in our iSeries is having a column added that we need to use in our SSRS reporting db.
I understand (from Making Schema Changes on Publication Databases) and the answer here from Damien_The_Unbeliever) that there is a default setting in SQL Server Replication whereby if we use a T-SQL ALTER TABLE DDL statement to add the new column to our table BUPF in the PION database, the change will automatically propagate to the subscriber db.
How can I check the replication of schema changes setting to ensure that we will have no issues with the replication following making the change?
Or should I just run ALTER TABLE BUPF ADD Column BUPCAT Char(5) NULL?

To add a new column to a table and include it in an existing publication, you'll need to use ALTER TABLE < Table > ADD < Column > syntax at the publisher. By default the schema change will be propagated to subscribers, publication property #replicate_ddl must be set to true.
You can verify if #replicate_ddl is set to true by executing sp_helppublication and inspecting the #replicate_ddl value. Likewise, you can set #replicate_ddl to true by using sp_changepublication.
See Making Schema Changes on Publication Databases for more information.

Related

Inheriting SQL Server table permission

I have a question about permission on the SQL server table. We have two SQL servers (sql-1, sql-2). The actual tables are on the sql-2, the synonyms to the actual tables are on sql-1 and the permission are set on sql-2.
I was not aware of this setup initially, so I took what I thought was a table on sql-1 at the time and did a INSERT into new table on sql-1, thinking I would inherit all the permissions. It did not. My question is when I was doing the Insert, even though the original table resides in sql-2, but when the insert is run on sql-1, would it not take the permission on sql-2 based on the synonym on sql-1 and apply it on the new table on sql-1?
The solution to my problem was to create the new table on sql-2, create the synonym on sql-1 pointing to sql-2 for the table, then set up the permission on sql-1 in the synonym itself on the new table in sql-2.

Database Access Mdb how to set a default value to existing column via SQL

I have a 12 years old mdb database and I was asked to add a new column to a table and set to a default value of "1".
My knowledge of asp/mdb is close to zero. I also have no Access or similar softwares.
I tried with:
ALTER TABLE Members ADD COLUMN Privacy Double Default 1
but generates error:
Error: An action query cannot be used as a row source.
Then I tried with:
ALTER TABLE Members MODIFY COLUMN Privacy VARCHAR(4) NOT NULL DEFAULT 'Yes';
but this also triggers another error:
Microsoft JET Database Engine error '80040e14'
How can I set an existing column to a default value?
Should I use an offline tool? If so which one?
Note: I also used an online tool to create the new column but it has no option to set a default value.
So I can either create the new column with the tool and set a default value with SQL, or do the creation of the column with the default value still with SQL.
I solved using AxBase from SourceForge.net.
I could properly open the *.mdb database and run the above SQL commands and they worked perfectly:
ALTER TABLE Members ALTER COLUMN Privacy SET DEFAULT 1
hi your access database is may be in office 2003 or office xp.
You can try to enable sql syntax and then try to run your query.
Tools -> Options -> Tables/Queries -> (At the bottom right:) Sql Server Compatible Syntax - turn option on for this database.
ALTER TABLE Members ADD COLUMN Privacy number Default 1

User created statistics adding dependency on columns on sql server

Recently I have dropped all automatically created statistics (named _WA_Sys_%) and run the following T-SQL command to create statistics for all columns of the database :
EXEC sp_createstats #indexonly = 'NO', #fullscan = 'FULLSCAN', #norecompute ='NO'
All worked fine, until I had to drop a column in a table, then an error 5074 occured, indicating that statistics should be dropped before dropping the column.
Is there a way to get SQL Server to drop silently user created statistics when a column is dropped ?
I don't think you can make SQL server do it silently, as this is a common problem for people using user statistics. There is a way to drop relevant statistics with a custom query - would it work for your needs?

Can't set auto-increment via SQL Server Express Management Studio?

I just tried inserting value in to a database and that work. Now I insert again and I get an error for identical primary key.
I can't find any option to alter it to be auto-increment.
I'm updating the table via Linq-To-Sql.
User u = new User(email.Text, HttpContext.Current.Request.UserHostAddress,
CalculateMD5Hash(password.Text));
db.Users.InsertOnSubmit(g);
db.SubmitChanges();
I didn't fill in the user_id and it worked fine the first time. It became zero.
Trying to add a second user, it wants to make the ID 0 again.
I could query the database and ask for the highest ID, but that's going to far if you know about auto-increment.
How can I turn this on? All I can find are scripts for table creation. I'd like to keep my existing table and simply edit it.
How is your Linq-to-SQL model defined?? Check the properties of the user_id column - what are they set to??
In your Linq-to-SQL model, be sure to have Auto Generated Value set to true, Auto-Sync set to OnInsert, and the server data type should also match your settings (INT IDENTITY),
In SQL Server Management Studio, you need to define the user_id column to be of type INT IDENTITY - in the visual table designer, you need to set this property here:
It is zero because you have a integer for a primary key column type. To use auto-increment, set tables identity column to the ID (selected in the table properties)
Would probably be easier to edit the database using VS if you have a version that will work for, otherwise if you have to edit it in management studio see this article:
http://blogs.msdn.com/b/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx
Or you can increment the user_id manually and pass it to the insert function if you cannot alter the property/table field description

how can i change a field in my SQL database from numeric(18) to varchar(10)

I have a zipcode field in a database that I just took over. Previously, it was set as a numeric field with 18 precision but I am trying to convert it over to varchar(10).
I need to make this change because the linq fields are coming in as decimal and are causing issues and i want to change the linq fields to simply be strings.
I tried this in SQL server enterprise manager but i get this error, saying:
that the table will have to be dropped and recreated. you have either made changes to a table that can't be recreated or enable the option to prevent saving changes that require a table recreation
Any suggestions?
to enable that option in SQL management studio uncheck the following option...
Tools / Options / Designers / Table and Database Designers / Prevent saving changes that require table re-creation
You could also run an alter statement to change your datatype (as long as all of your data will fit in a varchar(10) column).
ALTER TABLE MyTable
ALTER COLUMN MyZipCodeColumn VARCHAR(10)
Are you using MS-SQL 2008? Changes that require the table to rebuilt are blocked by default.
Click Tools->Options, then Designers. Uncheck "Prevent saving changes that require table re-creation".
Then you can change your column using the designer.
Screenshots on how to do it:
http://pragmaticworks.com/community/blogs/brianknight/archive/2008/06/04/sql-server-2008-designer-behavior-change-saving-changes-not-permitted.aspx

Resources