How to make new primary key on migration laravel 8 - database

So i want to make new primary key with datatype char and autoincrement in migration laravel 8 can anybody share your knowledge about this ? Cause im really confused with $table=id(); and the time stamp that cant be removed
Thank you

Related

CSV to SQL Server

In my csv files that I want to bulk insert into SQL Server, there's text (serial number) that's not in the .csv column format that I would LOVE to use as a primary key.
EX.
Data from Engine SQL03423,
version 21.04,
time, speed, temp
june 3 1:00, 90, 200
june 3 1:01, 69, 392
The SQL03423 I want to use as a primary key in my database.
However I get reports from this particular engine daily and if I get to use it as a primary key I'm sure I'll run into the issue of using the same primary key the next time I insert new data which will give me an error.
How do I get around this?
I need the serial number regardless even if it's not the primary key.
Also if I can't use it as a primary key, how do I create a "dummy" primary key into the target table that will autoincrement even if that particular column is obviously not in the csv files I'm importing? Is this even possible?
I am aware of stored procedures, views, etc in SQL. I have basic knowledge if that helps.
I'd suggest using an "artifical" primary key most of the time, which for your question means that you should go for an additional column instead of using the machine's serial number. Preferably, this should be an UUID (GUID) value instead of a simple INT. Why? Please have a look at this great post from Jeff Atwood explaining it: https://blog.codinghorror.com/primary-keys-ids-versus-guids/
Just add a line like this to your table declaration:
THE_IDCOL_NAME UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY
Find more about NewID() here: https://learn.microsoft.com/en-us/sql/t-sql/functions/newid-transact-sql
One of the great advantages of using UUIDs is that you do not have to worry about number ranges overlapping for ID generation. Example scenario from my experience: customer rents machines worldwide and the software logs usage information. Each site uses an idependent database that was being consolidated to the HQ database. If any of the sites would use overlapping number ranges as primary keys, they would have been into trouble. Using GUIDs solved this.

How to design this relaional database

I want to question about relational database. I have two tabel , They are airport_tbl and complain_tbl. Primary key of airport_tbl is airport_id and their fields are airport_name and airport_location. In complain_tbl I want to make airport_departure and airport_arrival and they are foreign key of airplane_tbl. Is is possible? Or dou you have other idea for designing this database? I will appreciate if you can help me. Thanks

How can I correct this entity association with Entity Framework Designer?

I have the Product entity with a foreign key for the Brand entity (both keys are int identity and primary keys in their own table, but idBrand is a foreign key in Products. I am using SQL Server as my db
I would want to add products without having to add a brand first, is there any way to do this without having to disable the foreign key at product?
I thought some ways of dealing with this, but maybe there is one better...
1) Do not use Foreign keys, only one more table with both ids and idproduct unique.
2) Do not use Foreign keys at Product, only a Brand id int that could be empty.
3) Create a dumb Brand with code 1 called "No Brand" or something.
To better understand me, I want to design the relationship without having the obligation of providing a Brand to the Product entity when coding. Is there a way of design this from the Entity Framework Designer in VS ?
Thank you for stopping by.
I found the solution for the problem, the association created in the designer was from 1 to many, I changed it to "0..1 to many", that solved the problem.
Thank you for reading.

data distribution based on primary key

Currently in one of my projects, we're supporting 32k entities, however it's reaching its limits for performance, and hence we're thinking of distributing it to different databases based on their integer primary keys. E.g. the first 35k will go to one db, the next 35k to the next db and so on (based on (primary key % #db) logic).
However, this will present a problem when we're inserting an entity into db. Since we don't know its primary key value beforehand, how do we figure out which db to insert it into?
One possibility is maintaining a global id table in only one db. So we insert into it first, get the primary key value and then use it to choose a db for further detailed insertion. But this solution is not uniform and hence difficult to maintain and extend. So any other thoughts on how to go about it?
Found this nice article that talks about how Flickr solved this problem:
http://code.flickr.com/blog/2010/02/08/ticket-servers-distributed-unique-primary-keys-on-the-cheap/

Date-based primary key instead of auto increment integer

I created a database with a field name ID and is serving as a primary key. Now i want it to be auto incremented on every new record entry, but on the basis of the date.
For ex. for date 5/7/2011, i want my value as, 001050711, 002050711....001050811, 002050811....(000-MM-dd-yy). I want to do it in Sql Server, but not in my c# programming. How to do it?
Seems like a peculiar Primary Key choice. There could also be strong potential for duplicate key values.
My advice, don't do it this way just because you can.
Perhaps you can share the business object/process it is that you are wanting to model?

Resources