primary-key

SQL: set existing column as Primary Key in MySQL

核能气质少年 提交于 2019-12-02 17:49:54
I have a database with 3 columns: id, name, somethingelse This table has no index set and i am getting "No index defined!" in phpmyadmin id is a 7digit alphanumeric value, unique to each row. I want to set Drugid to be the primarykey/index (i dont know the difference if there is one) Please explain in detail as i am new to this. Thank you. Either run in SQL: ALTER TABLE tableName ADD PRIMARY KEY (id) ---or Drugid, whichever you want it to be PK or use the PHPMyAdmin interface (Table Structure) ALTER TABLE your_table ADD PRIMARY KEY (Drugid); If you want to do it with phpmyadmin interface:

Generating a non-sequential ID/PK for a Django Model

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 17:31:05
I'm on the cusp of starting work on a new webapp. Part of this will give users pages that they can customise in a one to many relationship. These pages naturally need to have unique URLs. Left to its own devices, Django would normally assign a standard AUTOINCREMENT ID to a model. While this works fantastically, it doesn't look great and it also makes pages very predictable (something that isn't desired in this case). Rather than 1, 2, 3, 4 I would like set-length, randomly generated alphanumeric strings (eg h2esj4). 6 spots of a possible set of 36 characters should give me over two billion

Custom keys for Google App Engine models (Python)

蓝咒 提交于 2019-12-02 17:19:22
First off, I'm relatively new to Google App Engine, so I'm probably doing something silly. Say I've got a model Foo: class Foo(db.Model): name = db.StringProperty() I want to use name as a unique key for every Foo object. How is this done? When I want to get a specific Foo object, I currently query the datastore for all Foo objects with the target unique name, but queries are slow (plus it's a pain to ensure that name is unique when each new Foo is created). There's got to be a better way to do this! Thanks. I've used the code below in a project before. It will work as long as the field on

laravel: eloquent example insert data to database

点点圈 提交于 2019-12-02 16:22:59
I am sorry to ask this but I come from codeIgniter and have a really hard time understanding eloquent model insertion. This is a new way of working with models for me. i have read this article and understand some basics now. I have the following example. I have a product which has many attributes but the relevant one is brand and product name. (see the following example tables) products: id(PK),name,description,brand_id brands: id(PK),name Now here comes the problem. I know i can create a new brand and I know how I can create a new product. However I have no qlue how to connect the two

Primary & Foreign Keys in pgAdmin

给你一囗甜甜゛ 提交于 2019-12-02 16:07:13
I was wondering can some give me an explanation on how to assign primary and foreign keys in pgAdmin? I can't find any information online. For example...I've got a Student table with all their details (address, d.o.b. and etc.). I'm going to add a student_number to the table and make it a primary key. I just want to know how do I do that using pgAdmin? And if you may be kind to explain give me further information on using Primary Keys in postgreSQL (and pgAdmin). The same case with the foreign keys. There is no option in pgAdmin to add a column to an existing table and make it the primary key

MERGE SQL Server Primary Key Violation

久未见 提交于 2019-12-02 12:26:40
is there any chance that I can execute the below sql statement successfully? Currently, I'm receiving Primary Key Violation on my query below. What I want is that, when the first record was inserted in the target table and if there is another same primary key that will be inserted, it should be execute an UPDATE not INSERT to avoid the primary key violation, but I don't know to write it in actual sql script. As of know, I only have the below script. // User-Defined Tabled Type DECLARE @tvpEmailType dbo.EmailType INSERT @tvpEmailType VALUES ('mail@mail.com', 1) INSERT @tvpEmailType VALUES (

insert query with varchar as data type for primary key

你。 提交于 2019-12-02 09:27:52
The program is not accepting the query given below- public class loginDaos { public void create(loginBean bean) { ConnectionPool c = ConnectionPool.getInstance(); c.initialize(); Connection con = c.getConnection(); try { String sql = "INSERT INTO login VALUES(?,?,?,?)"; PreparedStatement pstmt = con.prepareStatement(sql); pstmt.setString(1, bean.getCode()); pstmt.setString(2, bean.getUserid()); pstmt.setString(3, bean.getPassword()); pstmt.setString(4, bean.getPosition()); pstmt.executeUpdate(sql); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String args[]) {

Get back the primary key value after insertion to db2 table by KeyHolder

二次信任 提交于 2019-12-02 09:23:50
Good day, I have a table in db2, where the primary is_autoincrement is set to Yes . Means that everytime insert data to this table, no need to pass in the primary key value, because it will auto generate. However, I need to get back the primary key value after insertion. The code is something as follow: public integer insertRecord() { //insertion sql code here KeyHolder keyHolder = new GeneratedKeyHolder(); PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory( getInsertBatch2( ), new int[] { java.sql.Types.TIMESTAMP, java.sql.Types.VARCHAR, java.sql.Types.SMALLINT,

Get field value of inserted row

大城市里の小女人 提交于 2019-12-02 09:21:28
问题 I want to write a function that returns the value of a column (in this case, an auto-incrementing primary key) for a row that it inserts. Essentially, I want to insert some new data, have a new primary key generated, then get that key. I could simply look for the highest primary key in the table, but it is possible that someone else could be running the function as well, and I could return the wrong key, right? What's the simplest way to negotiate this problem? 回答1: As pointed in the comments

Getting two issues while using stored procedure in MySQL

≯℡__Kan透↙ 提交于 2019-12-02 08:07:24
Below is the sample code of my Stored Procedure in which I am working on for interest calculation. This code is not executable because according to finding its getting issue while defining creating temporary table block before the cursor declaration but if I define same thing recently after cursor declaration then it's executing successfully. 1- My question is I am using that table inside cursor so I must have to define after cursor or I have missed anything ?? CREATE PROCEDURE `sp_interest_calculation_test`( IN sub_type CHAR(1) ) BEGIN DECLARE s_ledger_id INT; DECLARE s_start, s_end, s_tran