Adding a multi-column SQLite primary key

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

Can you check my syntax and correct it for me? I'm trying to create a primary key on the StoreName and ItemName columns of this SQLite table.

B4X:
objSql.ExecNonQuery("CREATE TABLE GroceryItems (" & _
    "StoreName TEXT DEFAULT ' ', " & _
    "ItemName TEXT DEFAULT ' ', " & _
    "LocationInStore TEXT DEFAULT ' ', " & _
    "IsleNumber TEXT DEFAULT ' ', " & _
    "LocationWithinIsle TEXT DEFAULT ' ', " & _
    "LocationHeight TEXT DEFAULT ' ', " & _
    "PRIMARY KEY (StoreName, ItemName) ' ' " & _
    ")")

Thanks.
 

Mahares

Expert
Licensed User
Longtime User
I would not go against anything NJDude recommends, but here is what you are looking for if you want to use your code:
B4X:
Dim objSql As SQL  'process globals

Dim txt As String    'in globals

objSql.Initialize(File.DirRootExternal, "MyShopping.db", True)  'created in root external
txt="CREATE TABLE GroceryItems (StoreName TEXT , ItemName TEXT , LocationInStore TEXT ,IsleNumber TEXT , LocationWithinIsle TEXT ,LocationHeight TEXT , PRIMARY KEY (StoreName, ItemName))"
objSql.ExecNonQuery(txt)
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Thanks Mahares.

I found with your help I messed up with the rounded bracket.


NJDude,
I'm going to try SQLite Studio. Can it work like SQL Server Management Studio?

It would be nice to connect to databases on the Android device from within SQLite Studio and perform test queries, etc.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I will experiment with it.

Glad to know there's something out there that will help in creating the queries.

Are there any other open source programs for us B4A developers?
 
Upvote 0

poseidon

Member
Licensed User
Longtime User
there is also a freeware based on .NET framework 2, no installation needed


B4X:
http://www.pipiscrew.com/works/sqlite-manager-v1-0/

be sure you watch the video tutorial
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Hi poseidon,

Thanks for the info. I use VS 2010. I hope it works with that version as well as the 2008 version the web site described.
 
Upvote 0
Top