sql-server

How to alter length of varchar in composite primary key?

In MSSQL I have a table created like this: CREATE TABLE [mytable] (fkid int NOT NULL, data varchar(255) CONSTRAINT DF_mytable_data DEFAULT '' NOT NULL); ALTER TABLE [mytable] ADD CONSTRAINT PK_mytable_data PRIMARY KEY (fkid, data); Now I want to increase the length of the 'data' column from 255 to 4000. If I just try: ALTER TABLE [...

SQL server concurrent accessing

Hi When sql server is receiving two queries (SELECT * From the_Same_Table), at exactly the same time, and if u have a server with multiple processors, Can sql server retrieve the data at the same time? I am trying to understand what will happen if a cheap select statement that finish within .01 sec, and 1000 users run the same query ex...

SQL Server 2008 - Database diagramm support objects cannot be installed ... Error

Hi! I tried to create a database diagramm with SQL Server 2008, but an error occurs: Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database ...

Design SQL Query for following case

Consider tables Table1 id, name 1 xyz 2 abc 3 pqr Table2 id title 1 Mg1 2 Mg2 3 SG1 Table3 Tb1_id tb2_id count 1 1 3 1 2 3 1 3 4 2 2 1 3 2 2 3 3 2 I want to do query to give result like id title 1 MG1 2 MG2 3 Two or More Ti...

login with admin and guest

ok i have my GUI installed on the server which has users as administrator as the role of an administrators and user1 which has the role of the guest... I have one project and there are different pages for administrators and guests... when the login screen comes up and the administrator logs in he should be redirected to the admin.aspx p...

Best way to copy a database (SQL Server 2008)

Dumb question - what's the best way to copy instances in an environment where I want to refresh a development server with instances from a production server? I've done backup-restore, but I've heard detach-copy-attach and one guy even told me he would just copy the datafiles between the filesystems.... Are these the three (or two, th...

Some of the tables in just installed AdventureWorks 2008 are empty.What's up?

Guys,i istalled this database, but all tables in Sales schema are empty (Sales.SalesOrderHeader for example). How this can be ? ...

SQL Server 2005, Replicating between timezones.

How does SQL Server handle the transfer of the datetime columns when replicating between timezones? ...

sql query - join that return only last row

I got a join select statement and i only need the last modified field in the second table. here's the select statement that i have now: SELECT NOM,PRENOM,OEDP.NUM_EMP,N_A_S,SIT_STATUT,PERMIS,DATE_EMBAUCHE,ADRESSE1,VILLE1,PROVINCE1,CODE_POSTAL1,TEL_RESIDENCE FROM ODS_EMPLOYE_DOSSIER_PERSONNEL AS OEDP JOIN ODS_SITUATION_POSTE AS OS...

Adding Mode to this SQL

I have this SQL for MS SQL Server 2008: WITH CTE AS ( SELECT e_id, scale, ROW_NUMBER() OVER(PARTITION BY e_id ORDER BY scale ASC) AS rn, COUNT(scale) OVER(PARTITION BY e_id) AS cn FROM waypoint.dbo.ScoreMaster WHERE scale IS NOT NULL ) SELECT e_id, cast(AVG (cast(scale as decimal(5,2))) as decimal(5,3)) as [AVG], cast (S...

All versions SQL Server Registry Key..

Is there any registry value that i could check to see if there is any version of SQL Server installed? I want to check a single value...not a value for 2005 another one for 2008 etc. ...

How to update two tables in one statement in SQL Server 2005?

I want to update two tables in one go. How do i do that in SQL Server 2005? UPDATE Table1, Table2 SET Table1.LastName = 'DR. XXXXXX' ,Table2.WAprrs = 'start,stop' FROM Table1 T1, Table2 T2 WHERE T1.id = T2.id and T1.id = '010008' ...

sql timezone calculation

I have a table which stores the storecodes and their timezone. Now based on a given local date, I need to know if that date converted to stores local date was a in a weekend or not. Now I already know how to get the weekend part. I am struggling with the conversion. I am actually confused. My table has for example the following two value...

Prevent SQL injection on free response text fields in classic ASP

I've got some free-response text fields and I'm not sure how to scrub them to prevent SQL injection. Any ideas? ...

Maximum number of columns in a table

Problem1: What is the maximum no of columns we can have in a table Problem2: What is the maximum no of columns we should have in a table ...

Returning a resultset from a stored procedure with a table value function or view

I am using SQL Server 2000 and feeling stuck about how to do this: I have a stored procedure that returns a single resultset which is bound to a gridview in a .Net web app. Now I'd like to have a "table" so I can use it in an existing VB6 application like this: SELECT * FROM myTable ...where the schema of "myTable" is reflects the...

How can I get the name of the database server from within a stored procedure?

I'm making complete connection strings inside my procedure and would like to inject the name of the database server in them. Is there any way that I can detect the name from inside or am I doomed to passing it in? ...

Find first non-null values for multiple columns

I'm attempting to get the first non-null value in a set of many columns. I'm aware that I could accomplish this using a sub-query per column. In the name of performance, which really does count in this scenario, I'd like to do this in a single pass. Take the following example data: col1 col2 col3 sortCol ==================...

Import/Sync Contacts from SQL Server to Outlook

Essentially I have a SQL Server (2008) database that contains contact information (among other things), and would like to provide the ability to view these contacts in Outlook. Outlook 2003 must be supported at minimum. The Outlook clients are connected to Exchange, so having the contacts available in Exchange (and then viewable via Ou...

Disable trigger hangs?

I need to do this from an ASP.NET web app: Alter Table Contacts Disable Trigger All -- Do some stuff Alter Table Contacts Enable Trigger All In some situations the Disable Trigger statement hangs. Where should I start looking to figure out what's causing this? If I restart SQL server it goes back to behaving normally. ...