+ Reply to Thread
Results 1 to 2 of 2
  1. Roaming teh Bytes OfWolfAndMan's Avatar
    Join Date
    Oct 2013
    Location
    Grandma's basement
    Posts
    869

    Certifications
    A/L/P/S+, CCNP R&S, CCDA, CCDP, CCNA R&S/Sec, ACIS ERS 8K & VSP 9K, BS: IT Security
    #1

    Default Help with MySQL syntax

    So I am new to SQL and using it for something at work.

    I have the following table I made:

    CREATE TABLE PC_Contacts
    (
    POC VARCHAR(255) PRIMARY KEY NOT NULL,
    Phone_1 VARCHAR(255),
    Phone_2 VARCHAR(255)
    );

    I import some data from a CSV into the table using the following command in powershell:
    cmd /c 'mysql -u root -p network < CSVImport.sql'

    After populating the table, something I noticed is when the last column (Phone_2) doesn't have a phone number populated, instead of inputting a NULL value, it is blank. In addition, several characters on the POC column are cut off whenever a phone number is omitted. So I input xxx-xxx-xxxx into the columns, repopulated it, and everything looked clean. How can I make it so I don't have to do this and the table can just populate itself with NULL values?

    +------------------+--------------+--------------
    | POC | Phone_1 | Phone_2
    +------------------+--------------+--------------
    |April Wilson| 123-456-7890 | xxx-xxx-xxxx
    |Anton Watson | 234-567-8901| 567-890-1234
    |Ashley Walker | 345-678-9012 | 456-789-0123

    Names and phone have been altered, of course .
    Reading: Lab Books, Ansible Documentation Goals: Bash Shell/Python Automation Refinement [], CCIE R&S Written [X], AWS Certified Solutions Architect Associate (Maybe) [] CCIE R&S Counter: Somewhere between zero and infinity
    Reply With Quote Quote  

  2. Member
    Join Date
    Oct 2015
    Location
    UK
    Posts
    98

    Certifications
    MCSD (Web), MCSA (SQL Server 2012/14), AWS Architect (Assoc.)
    #2
    I know very little about MySQL, but if I had that problem in MS SQL Server, I would add a "NULL" keyword to each of the column definitions that I wanted to be allowed to contain nulls.
    Reply With Quote Quote  

+ Reply to Thread

Social Networking & Bookmarks