Username Remember Me?
Password   forgot password?
   
   
insert column field data rather than the whole table
Posted: 30 November 2016 11:03 PM   [ Ignore ]  
Master
RankRankRank
Total Posts:  52
Joined  2010-05-27

Dear Developer,

the manual only provided the data inserting to a whole table.

Can you please provide an example how to insert the data into one field of the table with char type data?
then insert the rest fields of the table with float data type?

thank you!

Liwei

Profile
 
 
Posted: 01 December 2016 09:51 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  357
Joined  2008-04-26

Dear Liwei,

you can update only specific field(s) using the UPDATE SQL statement: Here we made simple table and then update only name of one person:

>> d=sddb('test.db')
perClass DB2 connections
>> sdsql(d,'create table data (id integer, name text);')

ans =

     
[]

>> insert(d,'data',{1,'Joe'5,'Bill'10,'John'12,'Betty'})

ans =

     
0

>> s=sdsql(d,'select * from data;')
4 by 2 set in 'test.db':
SQL='select * from data;'
>> +s

ans 


    
[ 1]    'Joe'  
    
[ 5]    'Bill' 
    
[10]    'John' 
    
[12]    'Betty'

>> s2=sdsql(d,'update data set name="Tom" where id=5;')

s2 =

     
[]

>> s=sdsql(d,'select * from data;')
4 by 2 set in 'test.db':
SQL='select * from data;'
>> +s

ans 


    
[ 1]    'Joe'  
    
[ 5]    'Tom'  
    
[10]    'John' 
    
[12]    'Betty'

With Kind Regards,

Pavel

Profile
 
 
Posted: 01 December 2016 05:12 PM   [ Ignore ]   [ # 2 ]  
Master
RankRankRank
Total Posts:  52
Joined  2010-05-27

Thanks. Can you please give an example to delete the table? also another example to delete all the data in the table?

Profile
 
 
Posted: 02 December 2016 01:41 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRank
Total Posts:  357
Joined  2008-04-26

Yes. Both can be achieved via SQL statements. To delete a table called data3 use:

>> s=sdsql(db,'drop table data3;')

https://www.tutorialspoint.com/sqlite/sqlite_drop_table.htm

To delete all records from a table data4, use:

>> s=sdsql(db,'delete from data4;')

Example e.g. at: https://www.tutorialspoint.com/sqlite/sqlite_delete_query.htm

Profile
 
 
Posted: 02 December 2016 04:06 PM   [ Ignore ]   [ # 4 ]  
Master
RankRankRank
Total Posts:  52
Joined  2010-05-27

Thanks for the links. But, Another request:

This is a query to get the record where the name is like Joe.
s = sdsql(database1, ‘select * from table1 where name like ‘’Joe’’’ )?

Now, I want a variable to pass this query.
var1=’Joe’
How to define this query to pass var1 into it?

any ideas?

Thanks!

thanks!

Profile