• 0

Make a cell unchangeable?


Question

22 answers to this question

Recommended Posts

  • 0

In the MySQL client I use, you make the cell a 'primary key' or 'key' to prevent the data being changed. I'm assuming it would be the same throughout all MySQL clients.

A primary key (and keys/indexes in general) do a very different thing to what you're suggesting... I don't know if you're doing it on purpose, but the advice you're giving out on these forums is really bad...

  • 0

Hi guys,

Simple question really - is it possible to make a cell unchangeable, or otherwise to lock it? Only 1 cell needed, but if row/table locking is possible, this is also an opktion.

Thanks! :)

You didn't say what in, but I think assuming some common dbms is safe. Most dbms's should allow users to be created and allow you to grant/revoke table/column level access to data. MySQL allows this. If you need to restrict access to specific records in a table, then this should be possible through the use of views.

  • 0

A primary key (and keys/indexes in general) do a very different thing to what you're suggesting... I don't know if you're doing it on purpose, but the advice you're giving out on these forums is really bad...

You asked how to make a cells data unchangeable, here's some information I picked up about keys from a google search

  • Always has a value (can not be null)
  • Has a value which remains the same (does not change)
  • Has a unique value for each record in the table

You asked a question, I replied with an answer, and other sources also back the information I told you.

I now know who not to offer my help to in the future, goodbye :)

  • 0

You asked how to make a cells data unchangeable, here's some information I picked up about keys from a google search

  • Always has a value (can not be null)
  • Has a value which remains the same (does not change)
  • Has a unique value for each record in the table

You asked a question, I replied with an answer, and other sources also back the information I told you.

I now know who not to offer my help to in the future, goodbye :)

-Alex- is actually entirely correct about the solution you proposed, keys/indexes have nothing to do with access restrictions or making data attributes read-only like you suggested.

  • 0

-Alex- is actually entirely correct about the solution you proposed, keys/indexes have nothing to do with access restrictions or making data attributes read-only like you suggested.

From the question he proposed, I thought he would have a cell that would hold a piece of data that will never be edited, hence the suggestion of a key.

I didn't think he wanted to protect a cell so that the data couldn't be edited; apologies.

  • 0

From the question he proposed, I thought he would have a cell that would hold a piece of data that will never be edited, hence the suggestion of a key.

I didn't think he wanted to protect a cell so that the data couldn't be edited; apologies.

even so, that is in no way what keys/indexes are for

  • 0

even so, that is in no way what keys/indexes are for

I'm guessing the rules for keys in Microsoft Access and MySQL are different then? If not, I think the education is flawed; if I've forgot this basic piece of information, I'm not sure how the hell I achieved an A* in 'Database software (creation and management)'.

My understanding of keys is, what I quoted in my last post, and that they are a pieces of information used to identify rows in a table. Going of this belief, and my use of keys I am perfectly correct. I always use keys in terms of user IDs, usernames, passwords etc. pieces of unique data that will never change.

  • 0

I'm guessing the rules for keys in Microsoft Access and MySQL are different then? If not, I think the education is flawed; if I've forgot this basic piece of information, I'm not sure how the hell I achieved an A* in 'Database software (creation and management)'.

My understanding of keys is, what I quoted in my last post, and that they are a pieces of information used to identify rows in a table. Going of this belief, and my use of keys I am perfectly correct. I always use keys in terms of user IDs, usernames, passwords etc. pieces of unique data that will never change.

You are correct in thinking that a primary key is used to uniquely identify a row/record, however there is nothing to stop them changing, the only requirement is that they remain unique within the set of records in that table. Also, you can only have one primary key per table.

  • 0

You are correct in thinking that a primary key is used to uniquely identify a row/record, however there is nothing to stop them changing, the only requirement is that they remain unique within the set of records in that table. Also, you can only have one primary key per table.

Ah, well my client doesn't let me edit cells which are assigned a primary key value, hence why I said it in my first post.

  • 0

Matteh, you're completely correct about primary keys being a unique ID assigned to a row (in combination with autoincrement)... but yes, I'm looking to protect a cell/column/table. Sorry for the way I wrote my post... I've been working on an overdue project from 5pm yesterday til 2pm today and I hadn't had any sleep.

You didn't say what in, but I think assuming some common dbms is safe. Most dbms's should allow users to be created and allow you to grant/revoke table/column level access to data. MySQL allows this. If you need to restrict access to specific records in a table, then this should be possible through the use of views.

The dbms was in the tag :p But yes, I should've mentioned it somewhere in the thread too. I'm running MySQL 5.5.19. As for column level locking, can you tell me a bit more about this?

What might complicate this more is that I want the access restriction to stand when the database is dumped and re-imported on to a different server... and I get the feeling that ain't possible.

  • 0

The dbms was in the tag :p But yes, I should've mentioned it somewhere in the thread too. I'm running MySQL 5.5.19. As for column level locking, can you tell me a bit more about this?

What might complicate this more is that I want the access restriction to stand when the database is dumped and re-imported on to a different server... and I get the feeling that ain't possible.

tags aren't shown on my mobile browser :p

you just need to check out the grant syntax: http://dev.mysql.com/doc/refman/5.5/en/grant.html

you can absolutely copy the privileges over, they're written in sql.

  • 0

Hi guys,

Simple question really - is it possible to make a cell unchangeable, or otherwise to lock it? Only 1 cell needed, but if row/table locking is possible, this is also an option.

Thanks! :)

Only way I can think of doing it would involve a trigger, which means MySQL 5.0 minimum. I assume you want it so it can't be changed with an UPDATE?

Here's an example. Change column_name, database_name to the applicable values and be sure to run the the entire SQL in one transaction.

DELIMITER $$

DROP TRIGGER column_name_readonly$$

CREATE TRIGGER column_name_readonly BEFORE UPDATE ON table_name
FOR EACH ROW BEGIN
SET NEW.column_name = OLD.column_name;
END;
$$

DELIMITER;[/CODE]

  • 0

Only way I can think of doing it would involve a trigger, which means MySQL 5.0 minimum. I assume you want it so it can't be changed with an UPDATE?

Here's an example. Change column_name, database_name to the applicable values and be sure to run the the entire SQL in one transaction.

<snip>

This worked perfectly! Thank you very much! :D

  • 0

Just out of time to edit, but in the end I used:

CREATE TRIGGER `copyright_readonly` BEFORE UPDATE ON `options`
FOR EACH ROW BEGIN
SET NEW.copyright = OLD.copyright;
END

CREATE TRIGGER `no_delete` BEFORE DELETE ON `options`
FOR EACH ROW BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'You cannot delete from this table!';
END

CREATE TRIGGER `no_insert` BEFORE INSERT ON `options`
FOR EACH ROW BEGIN
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'You cannot insert into this table!';
END

Just one more question... I presume a user could delete these triggers? What (if anything) would stop them from being able to do so?

  • 0

whether or not the dbms user has the 'trigger' privilege

What might complicate this more is that I want the access restriction to stand when the database is dumped and re-imported on to a different server... and I get the feeling that ain't possible.

  • 0

I won't be able to modify privs on the other server. It's to go to a client in the form of a load of .php files and .sql file... my client will have to setup the MySQL user herself. So obviously that user's gonna have all privs.

Guess I can't prevent it?

  • 0

I won't be able to modify privs on the other server. It's to go to a client in the form of a load of .php files and .sql file... my client will have to setup the MySQL user herself. So obviously that user's gonna have all privs.

Guess I can't prevent it?

create a php file to hold "config" data, have them stick the username in that; give them a php "setup" script that will take the username in the config file and issue the necessary create user and grant sql commands to set it up, which they can run after importing the sql file to create the actual database. if necessary, work out a suitable username for them beforehand, and ensure the existing user the setup will be run under has the necessary grant privileges itself. i don't know what you're doing about the existing user credential that was to be used, but you could perhaps have a login form displayed by the setup script that would take those credentials and use them to connect to the database with admin privileges to then create the users for your application (as specified in the config file).
This topic is now closed to further replies.
  • Posts

    • The Vibe Coding Playbook: Building Your Tech Business with AI —was $35, now FREE by Steven Parker Claim your complimentary copy (worth $35) of "The Vibe Coding Playbook: Building Your Tech Business with AI" for free, before the offer ends on June 23. Description A detailed and up-to-date walkthrough for entrepreneurs with limited (or non-existent) coding skills who want to build profitable software companies using new gen-AI tools. In The Vibe Coding Playbook: Building Your Tech Business With AI, renowned AI and data science educator Siraj Raval walks you through exactly what you need to do to build a technology business with generative AI-powered code assistants. Raval offers step-by-step guidance for non-technical professionals and entrepreneurs interested in creating scalable, profitable enterprises without spending years learning how to code. This book conceives of new artificial intelligence tools, like Cursor, as “co-founders,” lighting your way to constructing valuable software products and services. You’ll learn to build minimally viable products (MVPs), iterate on your software products as you develop and after launch, and grow your company while maintaining a lean, efficient, solopreneur-focused structure. Inside the book: Detailed guidance for entrepreneurs interested in creating powerful tech solutions for niche problems and markets without hiring expensive software developers Strategies for using generative AI tools to substitute for traditional technical co-founders Illustrative case studies from real-world founders who built successful technology businesses without learning to code Useful tools for non-technical entrepreneurs, including prompt libraries, decision trees, QR codes linking to video tutorials demonstrating key techniques, and access to an exclusive online community of like-minded founders Perfect for ambitious professionals and entrepreneurs who want to build a successful technology company now – using commercially available AI tools – The Vibe Coding Playbook is your personal roadmap to creating useful and profitable software for customers without learning how to code. How to download for free Please ensure you read the terms and conditions to claim this offer. Complete and verifiable information is required in order to receive this free offer. If you have previously made use of these offers, you will not need to re-register. Was $35, but is now FREE | Below free offer link expires on June 23. The Vibe Coding Playbook: Building Your Tech Business with AI The below offers are also available for free in exchange for your (work) email: The Vibe Coding Playbook: Building Your Tech Business with AI ($35 Value) FREE - Expires 6/23 The Persuasion Engine: How Any Business Can Use AI-Powered Neuromarketing to Understand and Win Customers ($28 Value) FREE - Expires 6/24 How to Do More with Less: Future-Proofing Yourself in an AI-driven Economy ($28 Value) FREE - Expires 6/30 Cloud Security Fundamentals: Building the Foundations for Secure Cloud Platforms ($131.95 Value) FREE - Expires 7/1 The Complete Free AI Learning: Master ChatGPT, Claude, Gemini & More ($21 Value) FREE How to Build an AI Design Workflow with Gamma ($21 Value) FREE The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
    • Rockstar confirms Grand Theft Auto VI pre-orders begin next week, unveils cover art by Pulasthi Ariyasinghe The release date of Grand Theft Auto VI has moved quite a lot since its original announcement in 2023, but it finally looks like the game has found its final launch slot. Rockstar today had a new video upload on its YouTube channel, and while it wasn't a new trailer for the game, the company revealed two things. This was the pre-order kickoff date for Grand Theft Auto VI as well as the game's official cover art. The company revealed that June 25 is when fans of the series will be able to pre-order their copy of Grand Theft Auto VI. Pre-orders will be available both digitally and in retail stores. The newly unveiled cover art shows off the two new protagonists, as well as a few more characters that are probably vital to the campaign storyline. Shots of vehicles players can use like a light helicopter, motorcycle, sports car, and speed boat are also seen here, alongside a shot of a crocodile. "Jason and Lucia have always known the deck is stacked against them," says Rockstar describing the campaign's protagonist duo. "But when an easy score goes wrong, they find themselves on the darkest side of the sunniest place in America, in the middle of a conspiracy stretching across the state of Leonida — forced to rely on each other more than ever if they want to make it out alive." Grand Theft Auto VI is coming to Xbox Series X|S and PlayStation 5 on November 19, 2026. A PC version has not been confirmed yet, though it's expected by many to land after the console release. When asked about this, the Take-Two CEO says it considers the core audience for the Grand Theft Auto franchise to be on consoles.
  • Recent Achievements

    • Week One Done
      Huge Trailer earned a badge
      Week One Done
    • Week One Done
      Classifyskilleducation earned a badge
      Week One Done
    • One Month Later
      eurospharma62 earned a badge
      One Month Later
    • Week One Done
      With What earned a badge
      Week One Done
    • Week One Done
      Harris Gilbert earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      552
    2. 2
      +Edouard
      169
    3. 3
      PsYcHoKiLLa
      72
    4. 4
      Michael Scrip
      64
    5. 5
      ATLien_0
      64
  • Tell a friend

    Love Neowin? Tell a friend!