Hello everyone, I just started learning sql and I came across a slight problem. Assume I have a customer table composed of the following fields: Customer_Number,Sname,Street,City,Postcode,credit_lim,balance.
What I want to do is to drop the Street,city,and postcode fields and add the following: fax,email,and phone.
Is it possible to use the following command:
Alter table customer Drop column street,city,postcode
Or should I do as following:
Alter table customer Drop column street
Alter table customer Drop column city
Alter table customer Drop column postcode
And the same goes to adding the phone,fax,and email field. Thank You.
NB: I need to use the Alter command and nothing else
Hi,I'm trying to run the ALTER TABLE command using a dynamic string for thetable, like so:DECLARE @TableName CHARSET @TableName = 'Customers'ALTER TABLE @TableNameADD ...blahIs this possible? We know this works:ALTER TABLE Customers ADD ...blahIt looks like I need a way to convert the CHAR value to a literal or perhapseven a table ID?Thanks in advance,Paul
Hi all, I am trying to do a very basic ALTER Command and am trying to change its DEFAULT value. Code below is what I currently have:
Code Snippet
ALTER TABLE Table_1
ALTER COLUMN TEST VARCHAR(1000) NULL DEFAULT 2
Thanks, Onam.
*UPDATE* I found this code but are there alternative methods? Additionally, if I was to update its DEFAULT value again how would I go about doing that? Do I first have to remove the CONSTRAINT and then run the command?
Code Snippet
ALTER TABLE Table_1 ADD CONSTRAINT DF_Albumns_Comment DEFAULT 2 FOR TEST
I used the code below to move the Model database and Model log file to new SAN drive locations. After running the commands I stopped the SQL server and moved the physical files to the correct location. Now I am unable to start SQL server, I get error 17204 Could not open file:Access is denied
I think the problem maybe that for FILENAME new_path I put "J:SQL ServerMSSQL.1MSSQLData" but did not include model.mdf in the file path.
How do I correct the path now that SQL service won't start? I have included the log file below.
ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name , FILENAME = 'new_path/os_file_name' )
2007-09-11 13:19:31.82 Server Microsoft SQL Server 2005 - 9.00.3042.00 (X64) Feb 10 2007 00:59:02 Copyright (c) 1988-2005 Microsoft Corporation Standard Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2) 2007-09-11 13:19:31.82 Server (c) 2005 Microsoft Corporation. 2007-09-11 13:19:31.82 Server All rights reserved. 2007-09-11 13:19:31.82 Server Server process ID is 3264. 2007-09-11 13:19:31.82 Server Authentication mode is MIXED. 2007-09-11 13:19:31.82 Server Logging SQL Server messages in file 'D:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLLOGERRORLOG'. 2007-09-11 13:19:31.82 Server This instance of SQL Server last reported using a process ID of 2648 at 9/11/2007 1:10:02 PM (local) 9/11/2007 8:10:02 PM (UTC). This is an informational message only; no user action is required. 2007-09-11 13:19:31.82 Server Registry startup parameters: 2007-09-11 13:19:31.82 Server -d D:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAmaster.mdf 2007-09-11 13:19:31.82 Server -e D:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLLOGERRORLOG 2007-09-11 13:19:31.82 Server -l D:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAmastlog.ldf 2007-09-11 13:19:31.84 Server SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required. 2007-09-11 13:19:31.84 Server Detected 4 CPUs. This is an informational message; no user action is required. 2007-09-11 13:19:31.96 Server Using dynamic lock allocation. Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node. This is an informational message only. No user action is required. 2007-09-11 13:19:31.98 Server Attempting to initialize Microsoft Distributed Transaction Coordinator (MS DTC). This is an informational message only. No user action is required. 2007-09-11 13:19:32.00 Server Attempting to recover in-doubt distributed transactions involving Microsoft Distributed Transaction Coordinator (MS DTC). This is an informational message only. No user action is required. 2007-09-11 13:19:32.00 Server Database mirroring has been enabled on this instance of SQL Server. 2007-09-11 13:19:32.00 spid5s Starting up database 'master'. 2007-09-11 13:19:32.09 spid5s SQL Trace ID 1 was started by login "sa". 2007-09-11 13:19:32.10 spid5s Starting up database 'mssqlsystemresource'. 2007-09-11 13:19:32.10 spid5s The resource database build version is 9.00.3042. This is an informational message only. No user action is required. 2007-09-11 13:19:32.26 spid5s Server name is 'SS02'. This is an informational message only. No user action is required. 2007-09-11 13:19:32.26 spid9s Starting up database 'model'. 2007-09-11 13:19:32.26 spid9s Error: 17207, Severity: 16, State: 1. 2007-09-11 13:19:32.26 spid9s FCB:pen: Operating system error 5(Access is denied.) occurred while creating or opening file 'J:SQL ServerMSSQL.1MSSQLData'. Diagnose and correct the operating system error, and retry the operation. 2007-09-11 13:19:32.26 spid9s Error: 17204, Severity: 16, State: 1. 2007-09-11 13:19:32.26 spid9s FCB:pen failed: Could not open file J:SQL ServerMSSQL.1MSSQLData for file number 1. OS error: 5(Access is denied.). 2007-09-11 13:19:32.26 spid9s Error: 5120, Severity: 16, State: 101. 2007-09-11 13:19:32.26 spid9s Unable to open the physical file "J:SQL ServerMSSQL.1MSSQLData". Operating system error 5: "5(Access is denied.)". 2007-09-11 13:19:32.26 spid9s Error: 17207, Severity: 16, State: 1. 2007-09-11 13:19:32.26 spid9s FCB:pen: Operating system error 5(Access is denied.) occurred while creating or opening file 'I:SQL ServerMSSQL.1MSSQLData'. Diagnose and correct the operating system error, and retry the operation. 2007-09-11 13:19:32.26 spid9s Error: 17204, Severity: 16, State: 1. 2007-09-11 13:19:32.26 spid9s FCB:pen failed: Could not open file I:SQL ServerMSSQL.1MSSQLData for file number 2. OS error: 5(Access is denied.). 2007-09-11 13:19:32.26 spid9s Error: 5120, Severity: 16, State: 101. 2007-09-11 13:19:32.26 spid9s Unable to open the physical file "I:SQL ServerMSSQL.1MSSQLData". Operating system error 5: "5(Access is denied.)". 2007-09-11 13:19:32.26 spid9s File activation failure. The physical file name "I:SQL ServerMSSQL.1MSSQLData" may be incorrect. 2007-09-11 13:19:32.26 spid9s Error: 945, Severity: 14, State: 2. 2007-09-11 13:19:32.26 spid9s Database 'model' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details. 2007-09-11 13:19:32.26 spid9s Could not create tempdb. You may not have enough disk space available. Free additional disk space by deleting other files on the tempdb drive and then restart SQL Server. Check for additional errors in the event log that may indicate why the tempdb files could not be initialized. 2007-09-11 13:19:32.26 spid9s SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.
Is it possible to use a variable to specify the filegroup in the ALTER/CREATE PARTITION SCHEME command?
I want the partition scheme to use the default filegroup for ALTER and CREATE PARTITION SCHEME. At the time the script is created, I don't know the default filegroup in the database.
My code:
declare @fileGroupName VARCHAR(50) = (select top 1 name from sys.filegroups where is_default = 1) ALTER PARTITION SCHEME MyScheme NEXT USED @fileGroupName
Is failing:
Incorrect syntax near '@fileGroupName'.
Q: Is it possible to use a variable for the filegroup in the ALTER/CREATE commands? Is so, what is the correct syntax?
Q: If using a variable is not possible, is there another way to specify the default filegroup?
Hi people,I?m trying to alter a integer field to a decimal(12,4) field in MSACCESS 2K.Example:table : item_nota_fiscal_forn_setor_publicofield : qtd_mercadoria integer NOT NULLALTER TABLE item_nota_fiscal_forn_setor_publicoALTER COLUMN qtd_mercadoria decimal(12,4) NOT NULLBut, It doesn't work. A sintax error rises.I need to change that field in a Visual Basic aplication, dinamically.How can I do it? How can I create a decimal(12,4) field via script in MSACCESS?Thanks,Euler Almeida--Message posted via http://www.sqlmonster.com
I would like to add an Identity to an existing column in a table using astored procedure then add records to the table and then remove the identityafter the records have been added or something similar.here is a rough idea of what the stored procedure should do. (I do not knowthe syntax to accomplish this can anyone help or explain this?Thanks much,CBLCREATE proc dbo.pts_ImportJobsas/* add identity to [BarCode Part#] */alter table dbo.ItemTestalter column [BarCode Part#] [int] IDENTITY(1, 1) NOT NULL/* add records from text file here *//* remove identity from BarCode Part#] */alter table dbo.ItemTestalter column [BarCode Part#] [int] NOT NULLreturnGOSET QUOTED_IDENTIFIER OFFGOSET ANSI_NULLS ONGOhere is the original tableCREATE TABLE [ItemTest] ([BarCode Part#] [int] NOT NULL ,[File Number] [nvarchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULLCONSTRAINT [DF_ItemTest_File Number] DEFAULT (''),[Item Number] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULLCONSTRAINT [DF_ItemTest_Item Number] DEFAULT (''),[Description] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULLCONSTRAINT [DF_ItemTest_Description] DEFAULT (''),[Room Number] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULLCONSTRAINT [DF_ItemTest_Room Number] DEFAULT (''),[Quantity] [int] NULL CONSTRAINT [DF_ItemTest_Quantity] DEFAULT (0),[Label Printed Cnt] [int] NULL CONSTRAINT [DF_ItemTest_Label Printed Cnt]DEFAULT (0),[Rework] [bit] NULL CONSTRAINT [DF_ItemTest_Rework] DEFAULT (0),[Rework Cnt] [int] NULL CONSTRAINT [DF_ItemTest_Rework Cnt] DEFAULT (0),[Assembly Scan Cnt] [int] NULL CONSTRAINT [DF_ItemTest_Assembly Scan Cnt]DEFAULT (0),[BarCode Crate#] [int] NULL CONSTRAINT [DF_ItemTest_BarCode Crate#] DEFAULT(0),[Assembly Group#] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULLCONSTRAINT [DF_ItemTest_Assembly Group#] DEFAULT (''),[Assembly Name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULLCONSTRAINT [DF_ItemTest_Assembly Name] DEFAULT (''),[Import Date] [datetime] NULL CONSTRAINT [DF_ItemTest_Import Date] DEFAULT(getdate()),CONSTRAINT [IX_ItemTest] UNIQUE NONCLUSTERED([BarCode Part#]) ON [PRIMARY]) ON [PRIMARY]GO
I am using sql server ce.I am changing my tables sometimes.how to use 'alter table alter column...'.for example:I have table 'customers', I delete column 'name' and add column 'age'.Now I drop Table 'customers' and create again.but I read something about 'alter table alter column...'.I use thi command but not work.I thing syntax not true,that I use..plaese help me?
Hi guys, If I have a temporary table called #CTE With the columns [Account] [Name] [RowID Table Level] [RowID Data Level] and I need to change the column type for the columns: [RowID Table Level] [RowID Data Level] to integer, and set the column [RowID Table Level] as Identity (index) starting from 1, incrementing 1 each time. What will be the right syntax using SQL SERVER 2000?
I am trying to solve the question in the link below: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2093921&SiteID=1
Thanks in advance, Aldo.
I have tried the code below, but getting syntax error...
ALTER TABLE #CTE ALTER COLUMN [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
I have also tried:
ALTER TABLE #CTE MODIFY [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
i am using visual web developer 2005 and SQL 2005 with VB as the code behindi am using INSERT command like this Dim test As New SqlDataSource() test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString() test.InsertCommandType = SqlDataSourceCommandType.Text test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@roll,@name, @age, @email) " test.InsertParameters.Add("roll", TextBox1.Text) test.InsertParameters.Add("name", TextBox2.Text) test.InsertParameters.Add("age", TextBox3.Text) test.InsertParameters.Add("email", TextBox4.Text) test.Insert() i am using UPDATE command like this Dim test As New SqlDataSource() test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString() test.UpdateCommandType = SqlDataSourceCommandType.Text test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll 123 " test.Update()but i have to use the SELECT command like this which is completely different from INSERT and UPDATE commands Dim tblData As New Data.DataTable() Dim conn As New Data.SqlClient.SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True") Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn) Dim da As New Data.SqlClient.SqlDataAdapter(Command) da.Fill(tblData) conn.Close() TextBox4.Text = tblData.Rows(1).Item("name").ToString() TextBox5.Text = tblData.Rows(1).Item("age").ToString() TextBox6.Text = tblData.Rows(1).Item("email").ToString() for INSERT and UPDATE commands defining the command,commandtype and connectionstring is samebut for the SELECT command it is completely different. why ?can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?if its possible how to do ?please help me
i am using a OLE DB Source in my dataflow component and want to select rows from the source based on the Name I enter during execution time. I have created two variables,
enterName - String packageLevel (will store the name I enter)
myVar - String packageLevel. (to store the query)
I am assigning this query to the myVar variable, "Select * from db.Users where (UsrName = " + @[User::enterName] + " )"
Now in the OLE Db source, I have selected as Sql Command from Variable, and I am getting the variable, enterName,. I select that and when I click on OK am getting this error.
Error at Data Flow Task [OLE DB Source [1]]: An OLE DB error has occurred. Error code: 0x80040E0C. An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E0C Description: "Command text was not set for the command object.".
Can Someone guide me whr am going wrong?
myVar variable, i have set the ExecuteAsExpression Property to true too.
Hi. I am writing a program in C# to migrate data from a Foxpro database to an SQL Server 2005 Express database. The package is being created programmatically. I am creating a separate data flow for each Foxpro table. It seems to be doing it ok but I am getting the following error message at the package validation stage:
Description: An OLE DB Error has occured. Error code: 0x80040E0C.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E0C Description: "Command text was not set for the command object".
.........
Description: "component "OLE DB Destination" (22)" failed validation and returned validation status "VS_ISBROKEN".
This is the first time I am writing such code and I there must be something I am not doing correct but can't seem to figure it out. Any help will be highly appreciated. My code is as below:
private bool BuildPackage()
{
// Create the package object
oPackage = new Package();
// Create connections for the Foxpro and SQL Server data
MessageBox.Show("The DTS package was not built successfully because of the following error(s):" + sErrorMessage, "Package Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);
I have SQL Server 7.0 running on both development and production boxes. The syntax below runs fine on my development box, but I am getting an error on my production box. Thanks for your help
ALTER TABLE SUPPORTINFO ALTER COLUMN STORENUMBER VARCHAR(20)
Error Message:
Server: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near 'COLUMN'.
Hi I'm trying to write a trigger to insert data into an archive file. I added a new trigger using database explorer, wrote the trigger and then saved it. The trigger has an error in it and I need to alter it. Can you tell me how to access the trigger ? Many thanks Chris
In my SQL SERVER 2005, sa login is enabled, despite Windows Authentication mode being set. When I'm trying to change it to disabled, I get the error "cannot alter 'sa' login. it doesn't exist or you don't have the permission" How can I change the status?
I have a database in SQL with the following collate name: SQL_Latin1_General_CP1_CI_AS... I am trying to change the accent sensetive to accent insensitive... how would I do this? I tried re-installing the SQL and setting the default to CI_AI, but since the database that is backed up uses CI_AS, the DB settings overrides the default settings...
Is there a way to add a column to an existing table and do it all in C#If my query string is as follows how do I execute the query?ALTER TABLE interests ADD COLUMN Swim VARCHAR(1) NOT NULL DEFAULT('n')ThanksMoonWa
I tried to do this myself, but couldn't figure it out since I am very unfamiliar with sql. I have a script that exports data from our store database to a file that is used to update our webstore database. I want to add a chunk to the script that will copy an image file from one directory to another as it loops through the database. I want to copy a picture from directory1 to directory2 that has a name SKU.jpg.
I was told in this forum by Ray Miao that the format of the statement would be:
My problem is that I don't know how or where in my script to place this statement so that it will work. If this is simplke and someone can tell me the setup that would be great. If not, I would be willing to hire someone to do what needs to be done to this script and send it to me. I can be reached at darren@jbjgifts.com or 217-369-2686.
Here is the script:
------------------------------------------------------------------- use TAMDATA go
set NOCOUNT on
/* GET SKUS THAT ARE NOT ON SALE HERE */ select s.sku SKU, s.Description Description, CONVERT(DECIMAL(9,2),s.SURetail) Price, null Weight, Replace(Replace(w.commentary,CHAR(13)+ CHAR(10),'<BR>'),Char(39),'') MarketingDescription, 'Yes' Taxable, v.Company+' '+c.description SoftCartCategory, null SoftCartTemplate, /*lower('template_'+REPLACE(v.company,' ','_')) SoftCartTemplate,*/ null VendorNo, null ListPrice, null Graphic, null Thumbnail, null SoftCartAttributes, ISNULL(s.vendstock,'none listed') vin, /*CONVERT(DECIMAL(6,0),(sl.OHUnits-sl.PRUnits-LYUnits-2)) InventoryQuantity,*/ CONVERT(DECIMAL(6,0),(sl.OHUnits-sl.PRUnits-LYUnits)) InventoryQuantity, v.company vn, cl.description cl, d.description dt, c.description ct, ISNULL(sz.description,'none listed') Size1, ISNULL(clr.description,'none listed') Color, ' ' OnSale, 'N' OnSaleNow
from SKU S, VENDORS V, CATEGORIES C, DEPARTMENTS D, CLASS CL, SKU_LOCATION SL, SKU_WEB_INFO W, SIZES SZ, COLORS CLR
wheres.skuid=sl.skuid and s.skuid=w.skuid and s.vendorid=v.vendorid and s.categoryid=c.categoryid and s.deptid=d.deptid and s.skuid=sl.skuid and s.classid*=cl.classid and /* May not be a Class Outer Join */ s.size1id*=sz.sizeid and /* May not be a Size Outer Join - presume only first size is used */ s.colorid*=clr.colorid and /* May not be a Color Outer Join */ /*(sl.OHUnits-sl.PRUnits-sl.LYUnits-2)>0 and */ /* available must be > 2 */ (sl.OHUnits-sl.PRUnits-sl.LYUnits)>0 and w.PublishToWeb=1 and sl.location=1 and /* JBJ has only 1 Location */ (s.SalePrice=0 or s.saleprice is null or getdate() < s.SaleStartDt or getdate() > s.SaleEndDt )
from SKU S, VENDORS V, CATEGORIES C, DEPARTMENTS D, CLASS CL, SKU_LOCATION SL, SKU_WEB_INFO W, SIZES SZ, COLORS CLR
wheres.skuid=sl.skuid and s.skuid=w.skuid and s.vendorid=v.vendorid and s.categoryid=c.categoryid and s.deptid=d.deptid and s.skuid=sl.skuid and s.classid*=cl.classid and /* May not be a Class Outer Join */ s.size1id*=sz.sizeid and /* May not be a Size Outer Join - presume only first size is used */ s.colorid*=clr.colorid and /* May not be a Color Outer Join */ /*(sl.OHUnits-sl.PRUnits-sl.LYUnits-2)>0 and /* available must be > 2 */*/ (sl.OHUnits-sl.PRUnits-sl.LYUnits)>0 and w.PublishToWeb=1 and sl.location=1 and /* JBJ has only 1 Location */ (s.SalePrice>0 or s.saleprice is not null) and getdate() between s.SaleStartDt and SaleEndDt /* Presumes this export will be run daily be Darren */ go --------------------------------------------------------------------
I would like to know how to alter a column to have a default value. For instance I have a column AreaCode Char(3) in a table. I have data in the table and now I want to add a default value of '123' to the AreaCode column.
I tried the following but did not work. Alter Table Phone Alter Column AreaCode Char(3) Default '123'