sql

user in database are not login after restoring the database

When i restored database from one server to other server the user's are not login in database but its shown in database then i delete it and make it again through sql/server/security/login and then its work. is someone tell me how can i restore database and do not define user every time... ...

is it good to have primary keys as Identity field

Hi , I have read a lot of articles about whether we should have primary keys that are identity columns, but I'm still confused. There are advantages of making columns are identity as it would give better performance in joins and provides data consistency. But there is a major drawback associated with identity ,i.e.When INSERT statement ...

getschema("Columns") + return DataType;

hello, i have this code using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); DataTable Databases = conn.GetSchema("Databases"); DataTable Tables = conn.GetSchema("Tables"); DataTable Columns = ...

How to drop a list of SQL Server tables, ignoring constraints?

I have a list of half a dozen MSSQL 2008 tables that I would like to remove at once from my database. The data has been entirely migrated to new tables. There is no reference in the new tables to the old tables. The problem being that old tables comes with loads of inner FK constraints that have been autogenerated by a tool (aspnet_regs...

Roll back in sql

I used rollback conceptn in my proceduer in dom table after execute then i ran the table like select * from dom but the query executed contionuosly not stopped how can i stop this pls help ...

Easy SQL query performance question

When designing an SQL query, which is faster, selecting the whole row (select *) or only the fields you need? What if the results were fed to another query (eg a natural join)? ...

Before trigger in SQL Server

I have 2 tables: survey (id(PK), name) and survey_to_topic (survey_id(PK,FK,not null), topic_id(PK,FK,not null)). When I try to delete from survey table, I get exception: "The DELETE statement conflicted with the REFERENCE constraint "FK_survey _to _topic _survey". The conflict occurred in database "mydatabase", table "dbo...

T-SQL DENY EXECUTE

hi what is the t-sql command/syntax to deny execute permissions to EVERYONE except the dbo on stored procedures? I want to grant execute to roles and users will then inherit rights based on the roles they belong to. as such i want new users to be denied execute on all the stored procedures i create. thanks sorry - i should mention i d...

How do indexes work on views?

Can someone please explain to me in simple English how an index on a view works? I have a fairly simple understanding of indexes on tables; how would indexing a view work differently from just letting the indexes on the underlying tables do their thing naturally? ...

Sql query split by a date range

I want to count the number of applications by a student split by month since their first application. Say I have the table structure as follows : Student ApplicationDate ------- --------------- Barry 2009-01-01 Barry 2009-01-20 Barry 2009-01-23 Barry 2009-02-01 Barry 2009-02-15 Barry 2009-03-...

using parameter in SQL with LIKE keyword

Hi folks, from my C#-programm, I access a SQL Server 2008 Database. I have a table with a fulltextindex and want to search for an indexed entry: SELECT page_id FROM page_categories WHERE page_title LIKE @title When 'title' has no withespaces everything is fine, but when title does contain withespaces, the request fails. It throws no ...

Execute multiple .sql scripts using c#

hi i want to run a script that calls multiple *.sql scripts i have multiple server in lots off sub office will need error control on script if the *.sql crashes also like to use a config file so i can edit for each site ta Gerard here some source code i have found using System.Data.SqlClient; using System.IO; using Microsoft.SqlServ...

Should you use temporary tables to pass data between stored procedures?

I have a number of search functions (stored procedures) which need to return results with exactly the same columns. This is the approach that was taken: Each stored procedure had the general structure: CREATE TABLE #searchTmp (CustomerID uniqueIdentifier) INSERT INTO #searchTmp SELECT C.CustomerID FROM /**** do actual search h...

return a default row in sql

Is it possible in oracle sql to return a default row if no rows found. I have a process where in rows fetched will be put in a flat ascii file. now i have a requirement that if there are no rows fetched by the sql query then there should be a default row in the ascii file. is it possible in sql to output a default row if no rows fetched...

Use Tablediff to compare all tables

Hi, I have recently discovered the tablediff utility of SQL Server 2005. I have 2 instances of the same database each on a different server. Is it possible to compare all tables using tablediff without having to replicate the same command while only changing the table name? For example, compare table1 on server1 with table1 on server...

Check whether two dates contain a given month

My problem is simple... or may be not. I've got a table that contains two dates: StartDate EndDate And I have a constant which is a month. For example: DECLARE @MonthCode AS INT SELECT @MonthCode = 11 /* NOVEMBER */ I need a SINGLE QUERY to find all records whose StartDate and EndDate includes the given month. For example: /* Ca...

How to tell if a SqlConnection has an attached SqlDataReader?

This is something now more of curiosity than actual purpose. If you have a SqlConnection opened and attach a SqlDataReader to it, and then try to run another query using the same SqlConnection then it will throw an error. My question is how does the SqlConnection know that a reader is attached to it. There is not a public property or any...

Datawarehouse duplicate dimension rows

We're starting to load up a datawarehouse with data from event logs. We have a normal star schema where a row in the fact table represents one event. Our dimension tables are a typical combination of user_agent, ip, referal, page, etc. One dimension table looks like this: create table referal_dim( id integer, domain varchar(255),...

Optional where clause / parameter in a SQL 2008 stored proc?

Hi everyone, I'm writing some code that updates a table. Depending on what the user wants to do, it either updates a large set of records, or a smaller one. The delineating factor is a group ID. The user can choose whether to update the table for all records, or just those with that groupID. I'd like to use the same stored procedu...

MySQL Trigger with Update

I'm trying to update a row when it gets updated to keep one of the columns consistant, CREATE TRIGGER user_country BEFORE UPDATE ON user_billing FOR EACH ROW BEGIN IF NEW.billing_country = OLD.billing_country AND NEW.country_id != OLD.country_id THEN SET NEW.billing_country = cms.country.country_name WHERE cms.country.country_i...