LeetCode-Notes
  • Introduction
  • Records of Practice
  • 关于Github 不支持密码问题
  • 面试题
    • 搜索广告
    • 多模态大模型
    • 刷题记录
  • 算法代码实现
  • Python
    • Python 笔记
  • Spark
    • PySpark
    • Spark Issues
    • Spark调优笔记
  • FeatureEngineering
    • Feature Cleaning
    • Feature Selection
    • Feature Transformation
    • Feature Crossing
  • Recommendation Algorithm
    • Recall-and-PreRank
      • Non-Negative Matrix Fatorization(NMF)
      • Fatorization Machine(FM)
      • User-base/Item-base实现
      • 多路召回实现
    • Ranking
      • NeuralFM
      • DeepFM
      • Deep&Cross network (DCN)
    • DeepLearning-Basic
      • Attention
      • Dropout
      • Batch Norm
  • Machine Learning
    • XGBoost
    • Cross Entropy Loss
    • Other models
  • Graph Neural Network
    • GNN-1-Basic
  • Big Data
    • Reservoir Sampling
  • SQL
    • SQL and PySpark functions
    • Query Film Infomation
    • Create, Insert and Alter Actor Table
    • Manage Employment Data
    • Manage Employment Data -2
  • DataStructure
    • Searching
      • Find power
      • 2 Sum All Pair II
      • Two Sum
      • Search in Rotate Array
      • Search In Shifted Sorted Array II
      • Search in 2D array
      • Three Sum with duplicated values
      • Median of Two Sorted Arrays
    • Array
      • Longest Consecutive Subarray
      • Merge Two Array in-place
      • Trapping water
      • Rotate matrix
    • Sorting
      • Merge intervals
      • 排序
      • 最小的k个数
      • Find TopK largest- QuickSelect快速选择 method
      • MergeSort Linkedlist
      • 第K大元素
    • LinkedList
      • Reverse LinkedList I
      • Reverse K-group linked list
      • Detect Start of Cycle
      • HasCycle
      • DetectCycle II
      • 链表的共同节点
      • 链表中倒数第k个节点
      • 删除链表倒数第k个节点
      • 合并两个链表
      • 在排序数组中查找元素的第一个和最后一个位置
      • 删除链表里面重复的元素-1
    • Tree
      • Find Tree height (general iteration method)
      • Check BST and Check CompleteTree
      • ZigZag Order traversal
      • Binary Tree diameter I
      • Maximum Path Sum Binary Tree
      • Maximum Path Sum Binary Tree II
      • Binary Tree Path Sum To Target III
      • Tree diameter 树的直径II
      • Tree ReConstruction
      • Check if B is Subtree of A
      • The Kth smallest in Binary Search Tree
      • 打印Tree的右视图
      • 二叉搜索树的后序遍历序列
      • 重建二叉树
      • 判断二叉树是否对称
      • Path Sum to Target in Binary Tree
      • Tree-PreOrder-InOrder-PostOrder
    • Heap&Queue
      • Top-K smallest
      • 滑动窗口最大值
      • Find the K-Largest
    • 合并k个已排序的链表
    • String
      • Reverse String
      • 最长不含重复字符的子字符串
      • 最长回文串
      • 最长回文子序列-DP
    • DFS/BFS
      • Number of island
      • Number of Provinces
      • All Permutations of Subsets without duplication
      • All Permutations of Subsets with duplication
      • Combinations Of Coins
      • All Subset I (without fixing size of subset, without order, without duplication)
      • All Subset of K size without duplication II
      • All Subset of K size III (with duplication without considering order)
      • All Permutation II (with duplication and consider order)
      • Factor Combination-质数分解
    • DynamicProgramming
      • DP-解题过程
      • Find Continuous Sequence Sum to Target
      • 1800. Maximum Ascending Subarray Sum
      • NC91 最长上升子序列
      • 查找string的编码方式个数
      • Maximum Product
      • Longest Common Substring
      • Longest Common Substring-II
      • minEditCost
      • Backpack I
      • Array Hopper I
      • Minimum distance between strings
      • 最大正方形
  • Big Data Algorithms
    • Big Data Processing Algorithms
      • Reservior Sampling
      • Shuffle
      • MapReduce
      • Bloom Filter
      • BitMap
      • Heap For Big Data
Powered by GitBook
On this page

Was this helpful?

  1. SQL

Create, Insert and Alter Actor Table

PreviousQuery Film InfomationNextManage Employment Data

Last updated 3 years ago

Was this helpful?

  1. Link

  1. Create , insert, alter, delete table

    1. 创建一个actor表,包含如下列信息

      CREATE TABLE IF NOT EXISTS actor (
      ACTOR_ID  SMALLINT(5)    not Null PRIMARY KEY,  # set primary key
      FIRST_NAME VARCHAR(45)    NOT NULL,
      LAST_NAME VARCHAR(45)     NOT NULL,
      LAST_UPDATE DATETIME          NOT NULL
      );

      列表

      类型

      是否为NULL

      含义

      actor_id

      smallint(5)

      not null

      主键id

      first_name

      varchar(45)

      not null

      名字

      last_name

      varchar(45)

      not null

      姓氏

      last_update

      date

      not null

      日期

    2. 批量插入数据

      INSERT INTO actor (actor_id,
                        first_name,
                        last_name,
                        last_update) 
      VALUES  (1, 'PENELOPE', 'GUINESS', '2006-2-15 12:34:33'),
              (2, 'NICK', 'WAHLBERG', '2006-2-15 12:34:33');
    3. 请你创建一个actor_name表,并且将actor表中的所有first_name以及last_name导入该表. actor_name表结构如下:

      列表

      类型

      是否为NULL

      含义

      first_name

      varchar(45)

      not null

      名字

      last_name

      varchar(45)

      not null

      姓氏

      CREATE TABLE IF NOT EXISTS actor_name (
      first_name varchar(45)    not null,
      last_name  varchar(45)    not null
      );
      
      insert into actor_name
       (select a.first_name, a.last_name
             from actor a);
      1. Note:

        1. insert into 如果 table的key已经有了会报错

        2. replace into 把已经有的key的数据进行替换,如果没有重复的key就会和insert into一样

        3. insert ignore into: 对于已经有的key,会直接忽略,不会更新

    4. 修改 table: 关键词'add', 'drop'

      # Add new Column
      alter table table_name add new_column_name datetime not null default('0000-00-00 00:00:00');       
      
      # example:
      alter table actor add create_date datetime not null default('0000-00-00 00:00:00');       
      
      
      # Delete Column
      alter table table_name drop column_name;  
      # example:
      alter table actor drop create_date;
    5. 删除table 记录: delete from table_name where

      1. 直接 delete from table_name : 删除所有数据

      2. 选择性删除: (delete和 query不能同时用,应该先query,再delete)

        delete from table_name where column_name in (
        select * from (
        #sub-query...
        )
        
        );
        
        
        # example:
        # 删除emp_no重复的记录,只保留最小的id对应的记录。
        delete from titles_test
        where id not in (
        select * from(
        select min(id)
            from titles_test
            group by emp_no
        ) a
        
        );
  2. Note

    1. SQL 对table的大小写敏感,但对table里面的column name大小写不敏感

    2. Insert 数据时,如果是直接用row 数据输入要加 table的column list以及 values (row1), (row2) ...; 但如果是从已有的table里面导入数据, 直接insert into table_name (select * from table ..);

    3. 关于 insert into 和replace into区别

      1. insert into 如果 table的key已经有了会报错

      2. replace into 把已经有的key的数据进行替换,如果没有重复的key就会和insert into一样

      3. insert ignore into: 对于已经有的key,会直接忽略,不会更新

牛客网 - 找工作神器|笔试题库|面试经验|实习招聘内推,求职就业一站解决_牛客网
Logo
MySQL DELETE 语句 | 菜鸟教程
Logo