I have a table that contains rows that I would like to delete based on a field and it's contents.
What is the correct syntax to script the removal of these rows based field parameter?delete tableA where fieldB = ?
Is that what you mean?|||Kinda. I only have one table and want to delete specific rows from that table that have a specific data within a certain field.
Let be more specific. I have a table (tableA) with 10 fields. Field 3 has data that does not conform to a datetime format and I would like to remove it. The field is currently a nvarchar(50) type (2003-10-10).
I want to remove rows that contain data that is looks like this
(0020-10-10). Make sense?|||delete from table where field3 ='0020-10-10'|||Perhaps you can use the ISDATE() function, which returns 1 if a string can be converted to a valid date, and 0 if it cannot.
Try this query:
select *
from YourTable
where ISDATE([Column3]) = 0
If this returns the rows you want deleted, then change the query to a delete query:
delete
from YourTable
where ISDATE([Column3]) = 0|||right but I forgot to mention, there are all kinds of variation of that date.
I ran a script that reads as follows to help identify data within a field that does not fit a date format->
SELECT * FROM findet WHERE ISDATE(servfrom) = 0
This gave me a list of records that are not in proper date format. Now, I would like to remove them from my table. Can I use the same,
delete findet where ISDATE(servfrom)=0|||See previous post.|||That worked like a charm, thank you!!
Showing posts with label contents. Show all posts
Showing posts with label contents. Show all posts
Thursday, March 29, 2012
Saturday, February 25, 2012
delete the record i want
hi
i am using vb6 and access. i have a form in which there is a adodc, a datalist OR a datagrid to view the contents of a table in an access file. i want to delete a particular record by selecting the row (in a datagrid) OR selecting the record in a datalist. how do i achieve this? pl help
onilHave the on_click action call a stored procedure to delete the record. Just pass the record id to the stored procedure and let it do the delete. You'll then want to refresh the dataset and control.|||hi
i tried but it always deletes (in both cases -datagrid and datalist) the first record BUT NOT the record i click on
onil|||ONIL,
you may want to post your question in the Delphi, Visual Basic, C etc forum. It looks like your problem is VB related, not SQL. What you want to know is how to find out which line of the datagrid was clicked.|||hi
thanks for the interest. i have solved the issue using the seek command
onil
i am using vb6 and access. i have a form in which there is a adodc, a datalist OR a datagrid to view the contents of a table in an access file. i want to delete a particular record by selecting the row (in a datagrid) OR selecting the record in a datalist. how do i achieve this? pl help
onilHave the on_click action call a stored procedure to delete the record. Just pass the record id to the stored procedure and let it do the delete. You'll then want to refresh the dataset and control.|||hi
i tried but it always deletes (in both cases -datagrid and datalist) the first record BUT NOT the record i click on
onil|||ONIL,
you may want to post your question in the Delphi, Visual Basic, C etc forum. It looks like your problem is VB related, not SQL. What you want to know is how to find out which line of the datagrid was clicked.|||hi
thanks for the interest. i have solved the issue using the seek command
onil
Sunday, February 19, 2012
delete records in tables
Is there any built-in tool that can delete tabel
records/contents in sql server? I can run delete from
tablename script, but there are two many tables. is there
an easy way?Look at this...
Declare @.sql varchar(8000)
set @.sql=''
select @.sql=@.sql + ' Truncate Table ' + name from sysobjects where
xtype='U'
EXEC(@.SQL) -- Truncates all tables
set @.sql=''
Select @.sql=@.sql + ' DROP TABLE ' + name from sysobjects where xtype='U'
EXEC(@.SQL) -- Drops all tables
HTH
"Matt" <spam@.spam.com> escreveu na mensagem
news:108001c3a920$524706e0$a101280a@.phx.gbl...
> Is there any built-in tool that can delete tabel
> records/contents in sql server? I can run delete from
> tablename script, but there are two many tables. is there
> an easy way?
>|||If you run the following SQL it will create a DELETE script for every table
that can then be ran.
SELECT 'DELETE FROM ' + TABLE_SCHEMA+'.'+TABLE_NAME + char(10) + 'GO'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
--
HTH
Ryan Waight, MCDBA, MCSE
"Matt" <spam@.spam.com> wrote in message
news:108001c3a920$524706e0$a101280a@.phx.gbl...
> Is there any built-in tool that can delete tabel
> records/contents in sql server? I can run delete from
> tablename script, but there are two many tables. is there
> an easy way?
>|||Hi,
Truncate table command will not succeed if there is FK relation ship. The
parent table will fail with below error,
Server: Msg 4712, Level 16, State 1, Line 1
Cannot truncate table 'table name' because it is being referenced by a
FOREIGN KEY constraint.
In this case you have to use delete command. (delete the child table using
Truncate command and use delete command for Parent table)
Thanks
Hari
MCDBA
"Wandenkolk T. Neto" <wandenkolkneto@.hotmail.com> wrote in message
news:#u4uRLSqDHA.688@.TK2MSFTNGP10.phx.gbl...
> Look at this...
> Declare @.sql varchar(8000)
> set @.sql=''
> select @.sql=@.sql + ' Truncate Table ' + name from sysobjects where
> xtype='U'
> EXEC(@.SQL) -- Truncates all tables
> set @.sql=''
> Select @.sql=@.sql + ' DROP TABLE ' + name from sysobjects where
xtype='U'
> EXEC(@.SQL) -- Drops all tables
>
> HTH
> "Matt" <spam@.spam.com> escreveu na mensagem
> news:108001c3a920$524706e0$a101280a@.phx.gbl...
> > Is there any built-in tool that can delete tabel
> > records/contents in sql server? I can run delete from
> > tablename script, but there are two many tables. is there
> > an easy way?
> >
>
records/contents in sql server? I can run delete from
tablename script, but there are two many tables. is there
an easy way?Look at this...
Declare @.sql varchar(8000)
set @.sql=''
select @.sql=@.sql + ' Truncate Table ' + name from sysobjects where
xtype='U'
EXEC(@.SQL) -- Truncates all tables
set @.sql=''
Select @.sql=@.sql + ' DROP TABLE ' + name from sysobjects where xtype='U'
EXEC(@.SQL) -- Drops all tables
HTH
"Matt" <spam@.spam.com> escreveu na mensagem
news:108001c3a920$524706e0$a101280a@.phx.gbl...
> Is there any built-in tool that can delete tabel
> records/contents in sql server? I can run delete from
> tablename script, but there are two many tables. is there
> an easy way?
>|||If you run the following SQL it will create a DELETE script for every table
that can then be ran.
SELECT 'DELETE FROM ' + TABLE_SCHEMA+'.'+TABLE_NAME + char(10) + 'GO'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
--
HTH
Ryan Waight, MCDBA, MCSE
"Matt" <spam@.spam.com> wrote in message
news:108001c3a920$524706e0$a101280a@.phx.gbl...
> Is there any built-in tool that can delete tabel
> records/contents in sql server? I can run delete from
> tablename script, but there are two many tables. is there
> an easy way?
>|||Hi,
Truncate table command will not succeed if there is FK relation ship. The
parent table will fail with below error,
Server: Msg 4712, Level 16, State 1, Line 1
Cannot truncate table 'table name' because it is being referenced by a
FOREIGN KEY constraint.
In this case you have to use delete command. (delete the child table using
Truncate command and use delete command for Parent table)
Thanks
Hari
MCDBA
"Wandenkolk T. Neto" <wandenkolkneto@.hotmail.com> wrote in message
news:#u4uRLSqDHA.688@.TK2MSFTNGP10.phx.gbl...
> Look at this...
> Declare @.sql varchar(8000)
> set @.sql=''
> select @.sql=@.sql + ' Truncate Table ' + name from sysobjects where
> xtype='U'
> EXEC(@.SQL) -- Truncates all tables
> set @.sql=''
> Select @.sql=@.sql + ' DROP TABLE ' + name from sysobjects where
xtype='U'
> EXEC(@.SQL) -- Drops all tables
>
> HTH
> "Matt" <spam@.spam.com> escreveu na mensagem
> news:108001c3a920$524706e0$a101280a@.phx.gbl...
> > Is there any built-in tool that can delete tabel
> > records/contents in sql server? I can run delete from
> > tablename script, but there are two many tables. is there
> > an easy way?
> >
>
Subscribe to:
Posts (Atom)