database,table,foreign-keys,q,kdb , KDB+ / Q table creation with foreign key


KDB+ / Q table creation with foreign key

Question:

Tag: database,table,foreign-keys,q,kdb

My question is about creating a table with q and using foreign keys. I know how to do it the following way

q)T1:([id:1 2 3 4 5]d1:"acbde")
q)T2:([id:1 2 3 4 5]f1:`T1$2 2 2 4 4)

But now lets say I want to create the table with the ! operator flipping a dictionary this way

q)T3:1!flip ((`id`f1 )!((1 2 3 4 5);(2 2 2 4 4)))

How can I set a foreign key to table T1s primary key with this way of creating a table.

Update

Well, I thought my upper example would be sufficient for myself to solve my actual problem, but unfortunately its not.

What if I have this lists of lists layout A and B

q)A:enlist 1 2 3 4 5
q)B:(enlist "abcde"), (enlist `v`w`x`y`z)
q)flip (`id`v1`v2)!(B,A)

How can I make the list A as foreign key to table T1?

Update 2

And how would I implement it if I have A coming from somewhere, not initializing it myself. Do I have to make a copy from the list?


Answer:

You can use the same syntax on the column values list:

q)T3:1!flip ((`id`f1 )!((1 2 3 4 5);(`T1$2 2 2 4 4)))
q)T3~T2
1b

Update:

Again for this case we can use the same syntax on the list -

q)A:enlist`T1$1 2 3 4 5
q)meta flip (`id`v1`v2)!(B,A)
c | t f  a
--| ------
id| c
v1| s
v2| j T1

Update2:

Same syntax applied to the variable name:

q)A:1 2 3 4 5
q)meta flip (`id`v1`v2)!(B,enlist`T1$A)
c | t f  a
--| ------
id| c
v1| s
v2| j T1

Related:


Event on dynamically created checkbox asp.net


c#,jquery,asp.net,table,checkbox
I started to programming with asp.net, I have a table with some checkboxses. The problem is, I can't create static tables, because this action is linked with some parameters. Anyway.. When I click on the First checkbox I want to invert the other checkboxes in this table. How can i...

ODBC ISAM_EOF without any reason


c#,database,odbc,cobol
I have a strange behavior with an ODBC Driver and the underlying COBOL database. The database driver is acuODBC of AcuCorp(now Microfocus), the database itself is a COBOL database. The DSN is a system DSN and works just fine. Via Access/Excel u can read/write data with the DSN successfully. In...

Is there a way to create a primary key and have it cascade into other tables without re-entering data into the new tables?


mysql,database,cascade
I am working on setting up a database and have created tables that cascade out like using the cascade on update for the foreign key. I have two tables being worked with to try to solve this. My tables are like this: create table Item(Item int(4) not null, EquipName varchar(20),...

CakePHP Unable to insert to database (datetime format)


database,datetime,cakephp,insert
I was new to Cakephp and I actually following the tutorial of the Blog tutorial however I didn't follow their database and try my own. Currently my database: My Model: class FypCakephp extends AppModel { //Table Name public $useTable = 'Report'; public $primaryKey = 'report_id';} My Controller: public function add()...

sql script to find index's tablespace_name only


sql,database,oracle
Trying to find the specific tablespace names that were created for indexes only. I don't want to see the tablespaces names that are already used for tables. Something like below, but i couldn't have it working due to syntax error. Can someone fix it? select tablespace_name from dba_indexes where tablespace_name...

Id in database using qt


database,qt,sqlite
I am new to qt. I have created a table in sql, and what I'm trying to do is to give an id whenever user adds data. For the first thing inserted it will be 1, second 2 and so on. So how to check what number was the last...

Database object with different data


sql,asp.net,asp.net-mvc,database,entity-framework-6
I'm making a web page in ASP.NET MVC which compares prices from different shops. I have a one-to-many with products and the shops, where the SHOP has one PRODUCT and a PRODUCT has many SHOPs, the problem is that the product is the same but the price is different. Example:...

SQL Server: checkident: “[S00014][2560] Parameter 3 is incorrect for this DBCC statement.”


sql-server,database
Using an SQL Server database. A lookup table is having 50 new items added to it using a database versioning tool so the same script will be run on all three databases. There is a Dev, QA, and Prod version of the database and because of political reasons prod can't...

Does Maria DB support ANSI-89 join syntax


sql,database,join,syntax,mariadb
Does Maria DB support ansi-89 join syntax? SELECT sites.site_id, sites.site_name, pages.page_id, pages.page_title FROM sites, pages WHERE sites.site_id = pages.site_id; or only ansi-92 syntax? SELECT sites.site_id, sites.site_name, pages.page_id, pages.page_title FROM sites INNER JOIN pages ON sites.site_id = pages.site_id; ...

Why am getting this error?: Unknown column 'firstname' in 'field list'


php,database,mysqli
if(isset($_POST["submit"])) { // Details for inserting into the database $id = htmlentities($_POST["id"]); $firstname = htmlspecialchars($_POST["firstname"]); $lastname = htmlspecialchars($_POST["lastname"]); $username = htmlspecialchars($_POST["username"]); $password = htmlspecialchars($_POST["password"]); // Dealing with inserting $query = "INSERT INTO `myDatabaseForAll`.`users` (`id`, `firstname`, `lastname`, `username`, `password`) VALUES (NULL, $firstname, $lastname,$username,$password)"; $result = mysqli_query($connection,$query);...

Table goes max height when screen is resized


javascript,html,css,ajax,table
I have a table that is generated with a min-height of 300px and a max-heigh of 650px which is perfect. The only problem is when i resize the window the table will stretch all the way down until all its values are shown. Its supposed to have a scroll bar...

for-loop add columns using SQL in MS Access


sql,ms-access,table,for-loop,iteration
I am trying to add n columns to a table, like in this example of code where n = 10: Sub toto() Dim db As Database, i As Integer Set db = CurrentDb() For i = 1 To i = 10 db.Execute " ALTER TABLE time_series " _ & "ADD...

ElasticSearch asynchronous post


database,post,asynchronous,elasticsearch,get
I'm posting data on my ElasticSearch database. I've noticed that data is not immediately available, it requires some milliseconds to show up in a GET request. I can live with that (after all, the calls are asynchronous so this behavior is expected) but in my test code I need to...

Displaying MySQL results in a single table


php,mysql,database
I created an interface in which the user can choose which results are going to be displayed. The options selected by the user are saved in an array, so the MySQL query goes through the different elements of this array. So I want to display the results in a single...

Speeding up a SQL query with indexes


sql-server,database,performance
I have a table called Products. This table contains over 3 million entries. Every day there are approximately 5000 new entries. which only happens during the night in 2 minutes. But this table gets queried every night maybe over 20 000 times with this query. SELECT Price FROM Products WHERE...

If I export my database with phpmyadmin will it lock my tables or take my database down?


mysql,database,phpmyadmin
I want to create a backup of my database using the phpmyadmin export function. the database can't have any down time so I need to know if running a database export will take the database down? I've looked on-line but all I get is instructions on how to export. No...

In simple RESTful design, does PATCH imply mapping to CRUD's (ORM's) “update” and PUT to “destroy”+“create” (to replace a resource)?


database,rest,http,orm,crud
I'm trying to create a simple REST API and map it to CRUD. I have an ORM (DataMapper) which has methods like create, update and destroy. If I get it right, given a resource {a:'foo',b:'bar',c:'baz'}, performing a PUT {b:'qux'} is supposed to replace the resource and result in the same...

echo both users


php,mysql,sql,database,loops
The code at the bottom of this post currently echoes: Name: Spongebob Squarepants Description: I live in a pineapple under the sea. Role: editor But there are two users in "wp_usermeta". It's only echoing one. The result needs to look like this: Name: wp_dev_05 Description: My name is Chris Topher!...

SQLite: Individual tables per user or one table for them all?


database,sqlite
I've already designed a website which uses an SQLite database. Instead of using one large table, I've designed it so that when a user signs up, a individual table is created for them. Each user will possibly use several hundreds of records. I done this because I thought it would...

Show and hide column in a table using drop down


javascript,jquery,html,table,drop-down-menu
I have a table, which looks exactly like this one: https://www.datatables.net/examples/api/show_hide.html I now want to replace the headers (the th things) with a drop down. I want to hide and show columns thanks to those drop downs (they can click and show what they want). I was also wandering if...

Foreign key in C#


c#,sql,sql-server,database
I have two tables, A and B, in a dataset in SQL Server; I have created a connection to the dataset in a c# project in visual studio. How can I create a foreign key ( A is the parent) between my two tables ? I want to create the...

SWT - show multiple table items


java,table,swt,tableviewer
Could anybody help me? I have a table in SWT and simply I want to show some table items but the table only shows one item and the others with vertical scroll. I want to show everything, without scrolling. I tried with the option SWT_NO_SCROLL but is not working. I...

Complex SQL with Multiple Joins


mysql,database,join
I have a database of politicians, political parties and candidacies for a post in the election. The database consists of the following tables: People, Groups, Candidacies and Posts. The Candidacies table is a join relationship between People and Groups. Each record in the Candidacies table represents a candidacy in the...

Difference between dba_SEGMENTS and dba_data_files


mysql,sql,database,oracle11g,oracle-sqldeveloper
Shouldn't these two queries give the same result? First is a sum of all segments while other is the sum of all data files. They are giving different results for me. While the first one gives me 149522MB, the other gives 214973.34 MB select sum(bytes)/1024/1024 MB from dba_segments; select sum(bytes)/1024/1024...

How to get node.js to connect to mongolab using mongoose


database,node.js,mongodb,mongoose,mongolab
I've been trying to use mongoose (module for node.js and mongodb). And tried to get a connection with mongolab up and running. I tried the following at the top of my app.js file, but I couldn't seem to enter the db.on function. global.mongoose = require('mongoose'); var uri = 'mongodb://username:password#####@ds.mongolab.com:#####/db'; global.db...

Formatting long-form survey data in R


r,table,formatting,reshape,long-form
We asked 3 people two or three yes-no questions. Let me denote these 3 people by 101,102,103 the questions by "A", "B","C" and the responses by 0, 1. The result is q<-data.frame(response=c(0,0,1,0,0,1,1), qstn=c("A","B","A","B","A","B","C"), person=c(101,101,102,102,103,103,103)) We need to convert this table to the following format person|qustionA|questionB|questionC 101 | 0 | 0...

Pull information from SQL database and getting login errors


php,sql,database
I am creating a very small, simple CRM for a company, they require the function to be able to view the last 25 orders via the dashboard. The orders are added via a Order-add form within the CRM. When adding the following code to the CRM I get an error:...

fill an html table by column instead of row?


html,css,table
'<table> <tr> <th>' .$varProduct[$x][0]. '</th>'. //this is a title '<th>' .$varProduct[$x][2] . $varProduct[$x][11] . ' </th> // this is a price </tr> </table>' this code makes a table that fills out like this Title Price Title Price Title Price but I want to fill it Title Title Title Price Price...

SimpleMembershipProvider WebSecurity.InitializeDatabaseConnection The login from an untrusted domain


asp.net,database,exception,model-view-controller
I export the database to the server and i've problem. When I start application i see this error An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. WebSecurity.InitializeDatabaseConnection("DefaultConnection",...

What type of database is the best for storing array or object like data [on hold]


database,node.js,sockets
I'm just curious what the best method would be if I'm trying to have a bot running on my Node server that I could play Blackjack against. But for multiple connected clients via sockets, each connected socket will have their own bot to play against but I need some way...

How do I display my mysql table column headers in my php/html output?


php,html,mysql,table,data
2 Questions... Scenario: I would like to query my database table via a form and then display the results that occur(if there are results) and my current situation is that it does work but it clears the form completely and leaves my to an empty page with just the results...

MySQL 4 Table Join


mysql,table,join
I've been trying to get the proper data for this 4-table join for awhile and I can't seem to pin it down. I'm trying to grab a list of ids from songs based on who I am following in follows, and show the song id if my followers are the...

select data according to Row in Sqlite


android,database,sqlite,android-sqlite
image i want to get the whole row i am using this code to get my desired data but its giving me null pointer exception at temp_address1 here is the code as in mentioned image i want to get the whole row matching phone number. how can i achive that...

How to use existing SQLite database in swift?


ios,database,xcode,sqlite,swift
I know there are some resources available for this but none of them clearly show the way how to do it properly. I have already populated .sqlite database (MTrader.db) and i want to connect it to my swift project and load the data from the database into spinner. I tried...

MySQL: Select several rows based on several keys on a given column


mysql,sql,database
I have this mysql table structure: ------------------------------------ | item_id | meta_key | meta_value | ------------------------------------ 159 category Bungalow 159 location Lagos 159 price 45000 160 category Bungalow 160 location Abuja 160 price 53500 ... 350 category Bungalow 350 location Lagos 350 price 32000 What I'd like to do is select...

Desktop Database with Server without installation


java,database,server,desktop,h2
i have Java-Application that growth a lot over the past month. All configurations from the programm and all the logs are stored in .txt or .log files. The programm should change now. The user could install the programm on his own pc but the programm itself should get all the...

ER diagram for booking database


database,database-design
I'm creating a database for booking apartments app. I have a question - it is allowable to keep user's passwords in DB (for example using BCrytp)? Another question - where is the best way to keep price if it may vary during several months?

How to Click All Inputs with the Same Class on Page Load


javascript,jquery,table,input,click
I have a table with multiple rows (hundreds) on my web page. Each table row has an input with the class name of act_inv. I am trying to get JavaScript/JQuery to click each input with the class name of act_inv. Is this possible? And if so, how may I do...

IBM Cognos _days_between function not working


mysql,database,date,cognos
I'm having an issue with Cognos 10. I'm trying to calculate the number of days between to dates so I use the _days_between( date1, date2 ) function. _days_between ([Derniere Date Changement diaphragme] , [Premiere Date Changement diaphragme]) I'm quite sure the two Dates are Date objects ( I set them...

Retaining original table formatting after a 'pagebreak'


excel,excel-vba,table,formatting,page-break
So here's the finished product, a statement of accounts with a working statement table, and an ageing analysis: Everything works great. It basically populates itself row by row with data from another table. Here is the sample code: j = 21 'First row on the statement of accounts workbook For...

HTML Table with 2 (two) rows set beside a 4 (four) row set


html,table
How would I achieve this table layout?

How to insert data into sql server database when the primary key column already set default identity(1, 1)


c#,table,insert
I'm trying to insert two data columns into my SQL Server database but I get an error at the code line -> cmd.ExecuteNonQuery(); Cannot insert the value NULL into column OrderID, table RestaurantApp.dbo.Junc_Order; column does not allow nulls. INSERT fails. The OrderID column is actually the primary key in my...

PreparedStatement.executeUpdate() doesn't insert in sqlite database


java,database,sqlite
i'm trying to make a DAO class for my Java project. I've a SQLite Database with only one table "USER". The schema is: CREATE TABLE USER( username VARCHAR(20) NOT NULL PRIMARY KEY, password VARCHAR NOT NULL, total_matches INTEGER DEFAULT 0, victories INTEGER DEFAULT 0, times_alien INTEGER DEFAULT 0, times_human INTEGER...

Combining two select statements


sql,database,select,where
I have two statements as such: var chgAssociationQuery1 = (from a in sostenuto.PROBLEMS join b in sostenuto.S_ASSOCIATION on a.SERVICEREQNO equals b.FROMSERVICEREQNO join c in sostenuto.Changes on b.TOSERVICEREQNO equals c.SERVICEREQNO where b.FROMSERVICEID == 101001110 && b.TOSERVICEID == 101001109 && a.NAME.Contains(name) select new { ProblemReqNo = a.SERVICEREQNO, ProblemId = a.SERVICEREQID, ChangeReqNo =...

How do I access website databases? [closed]


database
I'm trying to better understand databases and networking. Basically my question is how do websites like these access player data from the game when they're not affiliated with the company? Do you have to have permission by the website to read their statistics? Are these databases private? What are different...

Purging Database - Count purged/not-purged tables


mysql,sql,sql-server,database,stored-procedures
So I am working with a database where I will be purging various tables that contain rows that are older than 30days. I have fairly limited knowledge of SQL and wanted to know if there was a certain way to select the row that will be purged and the rows...

Improving work with SQL DataTime


sql,sql-server,database,tsql
I have a business in my Date. I need change date below for each date before 25 of each month I want get 25 of month before and for each date after 25 of each month I want get 25 of the same month. Example : for 2015/06/24 (or 2015/06/06)...

Order by count not sorting the records correctly?


php,mysql,database
I am using MySQL. I have two table i have attached the images of the both tables? When i apply ORDER by Count then the query retrieving result's from database but not sorting them correctly, i don't know what wrong i am doing? i searched some similar question in stack...

Creating a generic / abstract “DBContext” Class for shared functionality among different DBs


c#,database,generics,inheritance,abstract-class
I am working on a C# project that is pulling data from SQL Server, ODBC data-sources and Oracle Databases at different times. At this point, I have created 3 different classes - Once for each type of DB access. However, I am seeing that 95% of the code is identical...

creating stored procedure in mysql calculate profit from product table


mysql,sql,database,stored-procedures
My following code show some error: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN SET @v1:= (select sum( cost_price * current_stock) from product)' at line 2 CREATE PROCEDURE sp_profit BEGIN...