Gathering information to insert, update, or delete data

To insert, update, or delete data, you first need to know a few things about the table: 

  • The name of each column: You need to know the exact name of the columns because you will be using them to specify each column in your INSERT, UPDATE, or DELETE statements. These statements are commonly referred to as data manipulation language (DML) commands.
  • The order of the columns: This is especially important when you select data from another table to insert into a table.
  • The data type of each column: You need to know whether any of the data that you insert will fail because of a data type mismatch.
  • If the column is a part of a key or constraint: You need to be aware of any NOT NULL, default, unique, or CHECK constraints that are on the table that impact whether your data can be modified.You also need to be aware of any primary or foreign key constraints that prevent inserting, updating, or deleting data from your table.

To get the information in the preceding list, you can execute the following queries to get information about a table:

USE yourschema;
describe managers;

SELECT * FROM information_schema.table_constraints
WHERE table_name = 'managers'
AND table_schema = 'yourschema';

The first query in the previous code block gives you information about the table, such as column names, column types, whether they allow NULL values, whether they have a key associated with them, whether they have a default value, and any extras they may have, such as auto_increment, as shown:

The second query in the previous code block gives you information such as the schema, table and constraint names, what type of constraint there is, and whether a constraint is enforced or not, as shown:

If you want to see the definition of the CHECK constraints, you need to script out the definition of your table in MySQL. To view the CHECK constraint information, execute the following query:

USE yourschema;
SHOW CREATE TABLE managers;

The previous query returns the CREATE statement for the table in the database that you specified in the query. This way, you can examine the table definition to see all the information you need.

See the Further reading section for details on how to get this information in Oracle, PostgreSQL, and SQL Server. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.130.201