Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8691709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:10:30+00:00 2026-06-13T00:10:30+00:00

In SQLite for Android what is the correct way to add multi primary keys?

  • 0

In SQLite for Android what is the correct way to add multi primary keys?

Currently I have:

String Create_table = "CREATE TABLE project ( keyId INTEGER PRIMARY KEY, keyName TEXT PRIMARY KEY)";

The alternative method I thought of was:

   String Create_table = "CREATE TABLE project (keyID INTEGER, keyName TEXT, PRIMARY KEY(keyID, keyName))";

Are both valid? If so, which is better? Also how do I disallow NULL values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:10:31+00:00Added an answer on June 13, 2026 at 12:10 am

    No it’s not possible to create multiple primary keys for a single table. It’s basic rule of any SQL. However you can use other constraint like UNIQUE with index to achieve this.

    This won’t be valid SQL Syntax:

    String Create_table = “CREATE TABLE project ( keyId INTEGER PRIMARY KEY, keyName TEXT PRIMARY KEY)”;

    In other way you can create primary key for multiple column as follows:

    Create Table yourTableName (col1, col2, col3, PRIMARY KEY (col1, col2));
    

    How do I disallow NULL values?

    you can use NOT NULL Constraint , it will not allow you to enter NULL values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a collection of ids (sqlite Android), and a collection
Platform: SQLite on Android. Problem: table has three columns - id, title and order.
I was newbie in using sqlite database android. and now I have a problem
Possible Duplicate: How to convert MDB to SQLite in Android I have an MS
I have to execute the following query in Android SQLite UPDATE player SET rank=rank+1
The System-Time of my Android emulator is correct (currently 13:42). But when i use
I created database table in my android app. I used this query: CREATE TABLE
I'm using sqlite in android app and I want to make insert in table
This is for Android SQLite. I have two queries like this: select * from
I've created a SQLite Android dB in my app. I can add info to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.