I have many lines of existing data which seems to use a unique identifier column that begins with the letter K and is followed by 8 or 9 random numbers. I would like to use this column as the primary key in a table. For all future additions to the table I'd like to automatically generate a unique PK that follows the same format as the existing data. Is there a way to achieve this within SQL code, or would I need to create an elaborate (for my beginner level) Python function that generates the unique PK?
In SQL is it possible to create a serial primary key that begins with a specific letter and is followed by a specific amount of numbers?
476 Views Asked by MyErrorsRunethOver At
1
There are 1 best solutions below
Related Questions in SQL
- Can MVC.NET prevent SQL-injection at razor or controller level?
- SQL server not returning all rows
- When dealing with databases, does adding a different table when we can use a simple hash a good thing?
- Creating a parametrized field name for a SELECT clause
- Combine two rows based on common ID
- Column displays each count
- Slick query for one to optional one (zero or one) relationship
- Aggregate and count in PostgreSQL
- MAX and GROUP BY - SQL
- SQL statement for a tricky 2 table query
- How to create nested selects with sql?
- Pull and push data from and into sql databases using Excel VBA without pasting the data in Excel sheets
- Best Practice for adding columns to a Table in Oracle database
- SQL FIFO STACK using two tables
- SQL Query - Order by String (which contains number and chars)
Related Questions in POSTGRESQL
- Why does adding a JOIN completely modify the query planner behaviour?
- When dealing with databases, does adding a different table when we can use a simple hash a good thing?
- Aggregate and count in PostgreSQL
- Rails HABTM: Select everything a that a record 'has'
- Trigger using data from inserted row
- Select results where joined table contains records with an attribute, but without another
- DB candidate as CouchDB/Schema replacement
- How do I properly add data in SQLAlchemy?
- Postgres in Conda Environment (Ubuntu 14.04)
- How to customize the output of the Postgres Pseudo Encrypt function?
- Split a large query (2 days) into pieces to increase the speed in Postgres
- Why does pg_search prefix not work like I expect?
- extracting meta info from a table psql using information_schema
- How to query a table in the database and copy it's data into one one?
- Update a table using info from a second table and a condition from a third table in Postgresql
Related Questions in PRIMARY-KEY
- How to get primary key value with Entity Framework Core
- Showing MYSQL table columns with key types and reference
- MySQL: Using natural primary index or adding surrogate when tables are given
- Is it necessary to use an integer ID for the Country table when the name is already univocal?
- Entity Framework Code First from database not adding Key attribute
- Adding primary key to some exising tables in a database
- Finding primary key given relation and functional dependencies
- How to set "auto insert" foreign key value by using SQL Server?
- Python Pandas to_sql, how to create a table with a primary key?
- How to add a (primary) key to an existing table using SAP HANA
- creating a unique column in Linux (more like an sql primary key?)
- MySQL: is primary key unique by default?
- Is it possible to set an EF6 model's primary key value?
- php to return id using Scope_identity
- Include foreign key in composite primary key in Code-First Entity Framework
Related Questions in PRIMARY-KEY-DESIGN
- Allocate ranges of primary key integers
- Primary Key as domain username AND userID?
- MySQL - Using foreign key as primary key too
- Primary Key and Composite Key
- Are Primary Keys Recommended on a Timescale Hypertable?
- Why does an SQL table have multiple primary keys?
- SQL tables primary key
- Database design: Primary key from multiple data sources
- JSON object with id as primary key schema design
- ASP MVC code first create computed primary key
- In SQL is it possible to create a serial primary key that begins with a specific letter and is followed by a specific amount of numbers?
- Output Inserted or deleted in SQL Server
- Use of natural key in date dimension
- MySQL moving primary key from varchar to int
- REST API Primary Key Design MySQL
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
I would leave the existing rows as they are and continue with a different scheme for future rows, for example a plain number without letter (cast to a string). That can be generated with a sequence conveniently, and there is no risk of collisions.
Simplicity over perceived beauty!